Darwinbots Forum
Code center => Darwinbots Program Source Code => Topic started by: Zelos on October 08, 2005, 10:22:03 AM
-
I hope its ok to ask about VB that doesnt have to do with DB here.
Anyhow im wondering how its done to split a sentence. Like if I have Sentence "ABC" I should be able to split it up to 2 sentences that is like "A" and "AB"
how do I do?
-
Na, it's fine.
The character "_" spits a VB line across multiple lines.
For instance:
form1.caption = "Hello my name is! Hello my name is! Hello my name is" + _
"The Real Slim Shady."
-
no I mean, if I have a sentence like "Hi, my name is zelos" I want to have somekinda command that can store in a memory the letters between X and Y position, so between 5 and 8 in that sentence would be "my n", I want something like that
-
You want the mid, left, and right functions.
I think the syntax is:
left (string, length) = exerpt of the first length characters at the left of string.
Likewise with the others. Lookup mid's syntax, it's a bit different.
-
thx num, that were exacly what I needed. Nums, how do you make a graph like uve done in DB?
-
There isn't an easy way to do it. I'd check out the graph code in DB. I didn't program it, but I think it uses line segments...
-
ok, I´ll take a look, but nums, how do you check how long a sentence is in letters, like "hi" is 2 and "hello" is 5 and so on
-
strlen(yourstring)
strlen("hello") would be 5.
-
thank you
-
hey, it dont work
-
doesn't work how?
Show me what code doesn't work.
-
its Len("ABCDABC8") will give you 8. Not strlen...
-
ty
-
how do I make so that when you press a button (like calculate in my simple math program) a another menu apphere instant of the one before. But not so that I have 2 different windows
and another thing, how do I make the program run a sequens of orders every X seconds?
-
The "do something every X seconds" involves the timer... I'm not sure how to do it in VB. In C it'd be called "multitasking", and you'd set up different threads, and have one sleep for a second then execute... VB is way different.
When you say another menu, what do you mean?
-
Like in DB you have many different menus, some popup infront of the old menu when you press a command button, like advance cost. But instant of apphering infront of it I want it to replace it like when you swich from general to mutation in DB menus
-
You're still going to use different forms for that. I think it's soemthnig like this:
otherform.show(vbModal)
Or soemthing like that.
-
if you mean I have to make a new form that were what I were waiting for., with vbmodal you mean the name of the form right?
-
Use the tab strip item like we have in DB's options form.
Then you can just switch between tabs all you like.
Another way is to make items on your form invisible then just make them appear when you want them.
-
intersting ideas, ive figured out how the graph worx now, when I feel better im gonna show you something neat, but a question, if I use the line command to create a line, how do I make so I can remove it later?
-
plz can Py, Nums or someone else tell me how to remove the lines, When I know that I can finish my thing and show you guys.
-
I don't think you can treat the line as an object that can be deleted. You can clear a whole picture box though.
-
If you drew a line and want to remove it, you have a couple of options open to you.
First, you can redraw the same line in background color.
The problem with this is that it will leave gaps where your line crossed other objects.
A better idea is to have a routine that draws everything you need then call it from your program after clearing the entire window with the CLS command.
Just set your parameters to draw whichever lines you want, clear the whole thing then redraw it from your perameters.
-
strlen(yourstring)
strlen("hello") would be 5.
does strlen work with VB?
I always use len
len("hello") would be 5
-
I don't think you can treat the line as an object that can be deleted. You can clear a whole picture box though.
Actually you can make a line that is treated as an object. You can make it at design time, set its properties and stuff then modify it at run time. That way you can set its properties later (eg. line1.visible=FALSE)
Trouble is that I'm not sure how to draw a poly-line this way. Straight lines aren't much use on a graph :D
-
OK I should have said run-time lines can't be treated as objects :D
Maybe you could use an index array of line objects to make poly-lines?
-
probably better to use a one dimensional array to store all the points on a line then Pset them in a subroutine. That way we can delete them just as easy by Psetting them to background again.
You could get really clever and set the graphics mode so that they don't block overwrite. Maybe XOR them on. That way you can just XOR them right back off again and leave everything else unchanged.
Another way would be to set up an invisible graphics window or virtual space, draw everything there then Bitblt the whole thing to the foreground when it's ready. But that is a bit complex for relative beginners. :D
-
I like the idea of clearing the whole box, how do I do that?
-
picture1.cls
-
Assuming you are using a picturebox (named PictureBox1) to display the output graph. just use this command line
Picturebox1.CLS
That will clear all content in Picturebox1.
-
ok, what if I use Riquadro?
-
Do you mean for the name of your picturebox?
Doesn't matter what you call it. just put .CLS on the end of it.
-
Hey, I cant paint lines on the picture box, they disaphere behind it. btw, Riquadro is what is used in the DB graphes to have the graphes on.
-
I don't know what a riquardo is.
-
I have never really looked at the code for graphs in DB. I really don't like the way they work so I never use them.
If you want to make the lines appear on any object in VB you have to make sure that you address the object otherwise lines will just appear on whatever the current active object is.
Let me go look over the code a bit.
-
OK Riquadro is a rectangular "shape" object drawn onto a form named "Grafico"
Riquadro does not need to be used in any code. It is just four lines making up a rectangle, nothing more.
All drawing should be done with Grafico.
such as.....
Graphico.PSet (xo + xunit * 1, yo - yunit * data(k, t)), col
(taken from the RedrawGraph subroutine
the actual text is Me.PSet........etc. but that only works if the code is located inside the Grafico form.
-
but how do I remove all the lines with in it?
-
Graphico.CLS would sound about right from what PY has said.
-
I tried with the name of the thing . cls and it didnt work
-
Have you done:
formname.graphico.cls
if you are coding in another form or module?
-
Try to be more specific about what didn't work and what the code looks like, etc.
And make sure you haev "Option explicit" at the top of your VB code. It catches some programmign errors and forces you to be explicit with new variables, which is a good thing.
-
Graphico.CLS would sound about right from what PY has said.
Actually this would be extremely bad in this case since Grafico is the actual form. It has a bunch of other stuff on it too including the afore-mentioned rectangle.
All drawing in here is done directly onto the form itself rather than into a picturebox.
A general CLS would wipe the entire form.
It would be better to replace the rectangle shape with a picturebox then draw to it instead.
-
Have you done:
formname.graphico.cls
if you are coding in another form or module?
Shouldn't need to as Grafico is the form itself. This is the highest level object in VB
-
Oh right! Sorry I thought you meant grafico was a picturebox :redface:
-
I tried using the "line" command to create lines on a picture box but it didnt work :( should I do something to the picture box or command?
the line code look like thisLine (xo + Generationstepp * (N - 1), yo - Percentstepp * lastgene(1))-(xo + Generationstepp * N, yo - Percentstepp * Gene(1)), RGB(0, 100, 0)
-
I'm not 100% sure, but don't picture boxes have their own line commands?
so it would be:
pictureboxname.line(....
instead of just
line(....
-
really? ok I´ll give it a try then. lets hope ure right then im done and I can show you what ive been working on. so instant of line(blabla) I type ictureboxname.line(blabla) but I dont have to change the "blabla" right?
right now im not using this, but of curiosity, in a progressbar, how do I cchange so it increases/decreases?
-
I've never played with progress bars to be honest. I bet they have a member function called value, or something along those lines, and another that's max vaue.
So maybe you'd do progressbar.value = 30 or something like that.
-
Zelos alot of you questions can be answered by the 'Object Browser'.
It is located in 'View -> Object Browser', or just hit F2!
Here you can find (almost) all commands for Objects (picturesboxes etc.) and also other simple commands, though not all commands in VB is here (why I dont know).
In VB when you want to make something to an object (picturebox, text, label etc.) you often need to call their corresponding function:
example
'objectname.function parameters(for the function)'
For the progressbar, you set it by this:
(you can also set it in the properties on design-time, some objects have an additional properties window, to find it right click on the object in question, can choose properties, if it has an additional properties window it will popup)
'Sets the minimum for the progressbar
ProgressBar.Min = 0
'Sets the maximum for the progressbar
ProgressBar.Max = 10
'When you need the progressbar to increase in value you write
'Were x is the value it should be increased with.
'Beware that if the .Value, gets over .Max it will raise an error!
ProgressBar.Value = ProgressBar.Value + x
You need to threat all Objects/items in VB as real objects, like when you want to turn on you TV, you dont say just TurnOn... You need to use something like (okay I know, but it is just an analogy)
'If you use the remotecontrol
TV.RemoteControl.TurnOn = True
'If you push a button on the tv, it will be:
TV.TurnOn = True
(Bad example, but I hope it can be used to something)
-
Only if he has a version with a decent help file.
-
I'm not 100% sure, but don't picture boxes have their own line commands?
so it would be:
pictureboxname.line(....
instead of just
line(....
Sorry I thought I had explained that already.
Whatever object you want to do anything to has to be named in the command line.
To set a pixel in a specific picturebox, you have to name the picturebox object to do anything to it.
There are several ways to do this with objects.
First and easiest. To draw directly to a form (not an object inside a form) all you have to do is be inside the form code window then type a command line such as....
PSet (X, Y), color
Second method. Drawing to a picturebox that is inside the form in which the code is located.
PictureBox1.PSet (X, Y), color
Third method. Useful if you want to do a bunch of stuff to the same object.
With PictureBox1
.PSet (X, Y), color
.PSet (X1, Y1), color
End With
Fourth method. Drawing to a picturebox that is located in a form other than the one where the code is located.
Form1.PictureBox1.PSet (X, Y), color
You can also use "With" in that scenario too.
-
The object browser, will states all most all functions of a given object, be it picturebox, whatever.
-
Alot of it you need to figure out you self, but that way it gives alot more, or have I the misunderstood something!??
-
Right the object browser does give you all the members for each command so I guess it can be pretty useful.
You also get all this same stuff when you type in a command line.
-
Right:
objectname then type "."
A small popup of all members appears.
-
I figure out alot on my self. but sometimes it aint that easy when you cant find all commands on a list.
but thx anyway ^_^ with ur help I learn alot and get trough those things I cant figure out on my own
-
I think you're doing quite well for no programming background.
VB is nice that way. It isn't terribly impossible to pick up.
-
why thanks nums.
-
Just be sure when you finish a project you let others critique your code, or you'll get stuck in bad programming habits that will be difficult to break.
Not that there's only one right way to code, but there are definately some that are less right than others.
-
right now im happy it worx, but of course I´ll show you the programming so you can show how I can improve it. its rather primetive if you ask me
-
You would barf in absolute disgust if I showed you the first forms I started working on in VB. VB is a language that takes some practice to make look elegant.
-
I bet on that, practive gives perfection you know.
-
Here is my program, it is finaly working. or atleast I belive it does
you can change the amount of generations it show, how good a gene is, its frequens in the population. how many alleles it is, and sexes. What do you think guys?
-
Well I get an overflow whenever I click the graph button, no matter what values I put in...
-
0 values arent possible, with 2 alleles you need to fill gene A/B with 3 alleles All genes have to have values.
but the program is acting wierd since I changed it into a picturebox
-
Yes but I still get overflow.
-
strange, im using the same file and it worx for me. are you using half best or straight mode? if ure using half best you gotta give it a value aswell. else I have no idea. But here is the coding if you wanna take a look
just remember its my copyright
-
Works fine for me. Not a bad little program.
You have to enter values into all the genes text boxes or else it will crash. That is the only problem.
-
as I said, py how do I fix that?
-
Just add a bit of code that checks if any of these values are zero. If they are then display a message and "exit sub"
eg.
if A1.text="" then
msgbox("You must enter a value into the first gene before you can run the program")
exit sub
endif
just OR your conditions together to cover all 6 gene textboxes and you have a failsafe.
-
ok thx. I wonder if there is something wrong with the program or if its so that the lines are to small or if its so that they put over each other but sometimes the graphes aint showing
-
The showed every time I ran the program.
What conditions make them NOT show?
-
I'll totally DL and run it later today. Good work Zelos.
-
I ran with more than 2 sexes or more than 2 alleles. or both of them. but it might simply be that they are over each other or something.
thx nums, but I would be happy if you could come with how I could improve the coding to be more professional.
-
Actually it is better to use IsNumeric()-command, to check if there is any errors.
Exception handling, as I have stated before, everything that can be done wrong in a computer program, goes wrong. Somehow a user will always try to test the program in the most absurd ways, just to check if it works.
-
Darwinbots' GUI is that way. There's sparse little checking to see if the values are absurd or not.
-
how do you mean absurd? could you give an exemple?
just of curiosity, what data file on db source is the file that "paint" all the boits and show what happens? not proccesing all the things, just paint the bots and shots as we see them.
-
There are a series of commands that paint things graphiclly to the screen. I believe they are all in Form1.
DrawRob
DrawRobPer
etc.
They are all grouped together, shouldn't be difficult to find.
An absurd value would be 500000000 nrg per cycle to vegs. I don't think the program catches that.
-
there is nothing called Draw things.
-
No, there isn't. But DrawRob should exist. I knowDrawRobPer exists.
Looked at your code, I'm really impressed. Only things I'd recommend:
1. Indenting. It's a style thing only, has no effect on the code, but it makes it more readable. Look at Darwinbots' code for examples of when you would indent or unindent.
2. You would be better off grouping code into their own Subfunctions, that themselves call smaller syub functions, etc.
So that your main code would look like:
Setup
Do
CheckInput
UpdateGraph
loop while blah blah...
Like that, it makes the program look more professional. In the end, you'll have a tree of functions, that all call smaller functions, that call smaller functions, etc.
-
Num Num Num, too mutch collage brainwash:
Like that, it makes the program look more professional.
We are not worried about professional here, we are worried about user frandly. Thats why we do it.
I seen some professionals do some really stuped things when they code thinking its professional, thats why I hate .net so much.
-
Are you saying its better to place all the code in a single function :rolleyes:
There is one paradigm that overcomes all others in coding style: Make it readable! Make it readable to someone who knows nothing about your source, and make it readable to yourself 7 months from now when you have no idea what you were doing when you programmed the thing to begin with.
-
In this case you are correct Num.
-
I can't begin to tell you the number of times I've programmed something only to come back 6 or 7 months later and have no clue how it works.
Always Always Always try to make it as readable as possible. That's what really takes practice.
-
I agree. Infact happens to me often enough too. When I was 11 it did not happen to me , so I would not worry about it. Gess I have to start worrying about it now.
-
nums, I dont get what you mean with ur 2nd point, could you explain it a bit better?
and nums, whe ni look in the iersera file with VB, I dont find a file/form or what ever its called that is called anything with draw in it. I find datiriob,dna_help, database, dnaexcution , dnamanipulation and dnatokinization. but nothing draw, am I blind or am I looking at the wrong place?
-
Look in the form "Form1". There's a section inside it that does the drawing.
My second point... I'm not really good at explaining this. Basically it'd work like this:
Your main function only calls like 6 or 7 other functions. These functions are named something really basic. Then your main loop looks like:
do
Updatebots
Updateshots
Drawbots
Drawshots
loop
Or something like that. Then the Updatebots function looks something like:
for x = 1 to 1000
UpdateDNA
UpdatePhysics
next x
or something like that. You keep breaking the problem down into more and more sub functions. It makes the program more readable, and is what is generally considered "proper" programming technique.
-
are you talking about mdiform1? if so I´ll take a look at it. thx
-
Nope, Mdiform is different. This is called "Form1".
-
OH, now ive found it, now I feel kinda silly
-
AHA, I knew it. but still im supriced. I guessed you could use lines to paint bots like my graphes. and you suspected it would be like that, but still im surpriced.
-
The graphics you see during a simulation are all VB functions. Draw circle, etc.
Really, really basic.
-
yeah, but as a noob in programing im still kinda surpriced
-
That's part of why I'm porting it. OpenGL allows some raelly neat visual effects. Like for bioluminescence, you could actually show the bot glowing! How cool would that be.
-
that would be cool, porting? what does porting mean?
-
Porting means rewriting a program from one platform for another.
I'm rewriting the engine to use C++, since about half of the clock cycles currently are spent by Visual Basic doing things in C++ that would take a tenth of the time.
-
nice, very very nice, is there any big differenses between c++ and vb? I mean programming like
-
C++ has alot of things VB doesn't, but VB doesn't really have anything that C++ doesn't.
So I recommend learning VB first, and then making the switch to C++. 80% of C++ will make sense to you if you know VB already.
-
hmm, sounds like a good idea, and I can trust you?
btw nums a question, where do I find the file that loads a txt file and read it?
-
It's in HD_Routines or HDRoutines, I forget what I named it.
-
ok, how does the program calculate how many cycles that can go on each second? and if I have a toolbar with buttons, how do I add picture to them?
and if I sett a variable to public, can other files read it?
-
im experimitating now, but nums I have a problem. Take a look at this sinus program ive made. it shows a sinus curv when you press the buttom to the left. But why does it flimmer (is it called that in english?)? and how do I fix that?
-
It might help if you see the coding.
-
You need to zip all the project files together, not just give the main project file.
-
nemas problemas
-
Set the 'autoredraw' property for the picturebox to false.
-
it is false, but didnt you mean true? cause when I set it to true it vanished and another thing, in the condition I see things as condition(X as integer) what does that mean?
-
What condition?
-
any condition. like in db
Form_MouseDown(button As Integer, Shift As Integer, x As Single, y As Single)
and so on, btw that thing with the tool bar, ignore it. ive figured it out.
-
Those are the arguements passed to the function when it is triggered, if that's a good definition.
From your example, when a mouse button is pressed, the values in parenthesis are passed to the function for you to use. I.e. 'button' is the value corresponding to which button has been pressed, left or right. I'm not totally sure what 'shift' is, but 'x' and 'y' are the coordinates of the point the cursor was at when the button was pressed.
The 'As Integer' part means that the arguements are being passed to the function as integer-type variables.
Someone please correct me if any of this is wrong!
-
so the things with in the () is values passed from one function to another? thx
-
Maybe parameters is a better word than arguements, but yes.
-
You got it exactly Ulc. Nice explanation. :)
-
yepp, its very very sweet but how does the program calculate how many cycles it goes each second?
-
Every time a full cycle is implemented, it increments a counter somewhere.
There's a timer control in MdiForm that activates 1 every second. Upon evry activation, this timer checks to see how many cycles have happened since it last looked.
-
so you just let the program run cycles where it do all stuff, stuck it up and then it shows how many it were in a sec?
-
Right. You'll have to hunt down the ActiveX control that runs the time, I don't remember what it's called. Looks like a clock I think.
-
I know how to use a timer
-
Oh good. I think I looked at it once or twice, but it doesn't come up too often, so I'm a little fuzzy on how all it works.
-
on what file is the thing in db so you can add species and search on the drive?
-
It's in options form I think.
Go to the actual graphical form for options. Click on the "add species" button. That should take you to the text code that handles it.
-
ok, but what is "CommonDialog1" for thing? is it something in VB or just something in db? and what does it do?
-
CommonDialog1 is an instance of a common dialogue control.
Dialog controls are those "where is the file you're looking for" dialogue boxes.
-
so its a vb thing?, nums is there a way to change the case in a sentence so all parts is lower case?
-
It's quite possibly
lcase(string)
where string is the arguement.
-
That was what I thought too but when I looked it up int the help files it looks like this only applies to ODBC database interactions.
Haven't had the time to test it yet to find out.
Another possibility is Lower(string)
-
ive been starting to experimentate with commondialog, when ive open a file with it like this:
Private Sub Command1_Click()
CommonDialog1.ShowOpen
End Sub
how do I make so it apphere in a text box or stored as a string?
-
Now we're getting into areas of VB I'm still fuzzy in.
-
I don't get the qustion:
Private Sub Command1_Click()
CommonDialog1.ShowOpen
End Sub
how do I make so it apphere in a text box or stored as a string?
You mean how do you get the path into a string? It is :
FileName Property
Returns or sets the path and filename of a selected file. Not available atdesign time for the FileListBox control.
CopyLeft msdn only in the case of needing that a person gets msdn.
-
I think Bots is saying that it'd be:
Private Sub Command1_Click()
CommonDialog1.ShowOpen
End Sub
some_string = CommandDialog1.FileName
-
thx, a question,m if I have a list, how do I with commands add something to the list?
-
GET MSDN GOD DAM IT.
Private Sub Form_Load()
List1.AddItem "moo"
List1.AddItem "beee"
End Sub
-
^_^ this is getting fun ^_^
the thing is that a human is easier to understand. and another thing, when I use this to open a txt file:
Private Sub Command1_Click()
CommonDialog1.ShowOpen
Open CommonDialog1.FileName For Input As #1
Input #1, variable1
Text1.Text = variable1
Close #1
List1.AddItem CommonDialog1.FileName
End Sub
it only shows in text1 the first row, wgy? and how do I fix it?