trackbar to change vensim Constant variabl in Visual Studio

Use this forum to post Vensim related questions.
Post Reply
Paul Anim
Junior Member
Posts: 19
Joined: Thu Jun 09, 2011 12:19 am

trackbar to change vensim Constant variabl in Visual Studio

Post 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
tomfid
Administrator
Posts: 3988
Joined: Wed May 24, 2006 4:54 am

Re: trackbar to change vensim Constant variabl in Visual Stu

Post 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
Paul Anim
Junior Member
Posts: 19
Joined: Thu Jun 09, 2011 12:19 am

Re: trackbar to change vensim Constant variabl in Visual Stu

Post 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? :?
Administrator
Super Administrator
Posts: 4832
Joined: Wed Mar 05, 2003 3:10 am

Re: trackbar to change vensim Constant variabl in Visual Stu

Post by Administrator »

Try

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

result = vensim_command(str_VensimCommand)
Advice to posters seeking help (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391

Units are important!
http://www.bbc.co.uk/news/magazine-27509559
Administrator
Super Administrator
Posts: 4832
Joined: Wed Mar 05, 2003 3:10 am

Re: trackbar to change vensim Constant variabl in Visual Stu

Post by Administrator »

PS, you might need to make use of the STR() function to convert the TrackBar1.Value into a string.
Advice to posters seeking help (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391

Units are important!
http://www.bbc.co.uk/news/magazine-27509559
Paul Anim
Junior Member
Posts: 19
Joined: Thu Jun 09, 2011 12:19 am

Re: trackbar to change vensim Constant variabl in Visual Stu

Post by Paul Anim »

it worked

thanks :D
Post Reply