Page 1 of 1

trackbar to change vensim Constant variabl in Visual Studio

Posted: Tue Jun 28, 2011 12:43 pm
by Paul Anim
Hi,

I am trying to programme in Visual Studio 2008. I am trying to change vensim Constant variable value using trackbar control in Visual Studio 2008.

I have assigned the maximum, minimum and the tick frequency to the trackbar control. When i run the code and use the trackbar control, the values change corresponding to the the position of the trackbar. This means that the trackbar is working.
The bproblem is how to assign the trackbar value to the vensim constant variable so that when i run the simulation, the vensim contant varible's value will be that ot the value generated by the trackbar control.

Below is the code in Visual studio that am working with

Dim result As Object
Dim result1 As Object
Dim value As Integer
TrackBar1.Maximum = 6
TrackBar1.Minimum = 0
TrackBar1.TickFrequency = 1

TextBox1.Text = TrackBar1.Value
value = TrackBar1.Value

result = vensim_command("SIMULATE>SETVAL|Initial rate of capacity utilization=TrackBar1.Value")

result1 = vensim_command("SIMULATE>GETCNSTCHG|Initial rate of capacity utilization")

Can some one help me with this code? :(
Thanks

Re: trackbar to change vensim Constant variabl in Visual Stu

Posted: Tue Jun 28, 2011 2:57 pm
by tomfid
I'm not a VB guru, but I think I see your problem. Because TrackBar1.Value is inside the quotes in your command string,

result = vensim_command("SIMULATE>SETVAL|Initial rate of capacity utilization=TrackBar1.Value")

VB will take it literally and call Vensim with,

SIMULATE>SETVAL|Initial rate of capacity utilization=TrackBar1.Value

which won't be understood.

I don't know the VB syntax, but essentially you need to construct a string first, which is the concatenation of "SIMULATE>SETVAL|Initial rate of capacity utilization=" with the string value of TrackBar1.Value, and pass the result as your command.

Tom

Re: trackbar to change vensim Constant variabl in Visual Stu

Posted: Tue Jun 28, 2011 5:31 pm
by Paul Anim
Thanks Tom,

unfortunately, I am not a vb guru either and eventhough i believe your suggestion would work, I have no idea on how to do that.

Can someone help me with a working vb code? :?

Re: trackbar to change vensim Constant variabl in Visual Stu

Posted: Tue Jun 28, 2011 7:12 pm
by Administrator
Try

str_VensimCommand = "SIMULATE>SETVAL|Initial rate of capacity utilization=" & TrackBar1.Value

result = vensim_command(str_VensimCommand)

Re: trackbar to change vensim Constant variabl in Visual Stu

Posted: Tue Jun 28, 2011 7:14 pm
by Administrator
PS, you might need to make use of the STR() function to convert the TrackBar1.Value into a string.

Re: trackbar to change vensim Constant variabl in Visual Stu

Posted: Mon Jul 04, 2011 1:51 pm
by Paul Anim
it worked

thanks :D