Visual Basic 2010 Questions

Associate
Joined
14 Oct 2009
Posts
502
Location
Newport, Shropshire
Hi all,
Recently started computing and am building my own Army Building software for Warhammer 40k via Visual basic.
however i have run into an issue.
Basically i have the total of the army at the bottom, to add a unit to the army you press a button then select the unit, each unit is given a number, then you enter the quantity of the unit, then it displays the unit you have chosen in one text box and the points cost of that one unit on the other text box. The issue i have is that if you put in a unit in say Elite slot 1 which is say 280 points. And then change it to a different unit which costs say 280 points again the army total will be 560 points, rather than when you press the button to change the selection it resetting the points cost.

Dim Elite1 As Integer
Dim Elite1Qty As Integer
Dim Elite1Total As Integer

Elite1 = InputBox("Please Input your elites choice, 1 = Pariah, 2 = Flayed one and 3 = Immortal ")

If Elite1 = 1 Then
Elite1Qty = InputBox("Input the number of pariahs you want")
Elite1Total = (Elite1Qty * 36)

Elite1_txt.Text = ("Pariahs x " & Elite1Qty)
End If

If Elite1 = 2 Then
Elite1Qty = InputBox("Input the number of Flayed ones you want")
Elite1Total = (18 * Elite1Qty)

Elite1_txt.Text = ("Flayed ones x " & Elite1Qty)
End If

If Elite1 = 3 Then
Elite1Qty = InputBox("Input the number of Immortals you want")
Elite1Total = (28 * Elite1Qty)

Elite1_txt.Text = ("Immortals x " & Elite1Qty)
End If

If Elite1 replace Then


End If

Elite1Totaltxt.Text = Elite1Total
Army_total = Army_total + Elite1Total
Armytotaltxt.Text = Army_total

This is the piece of code. I am running the Army total at the end of all the IF statements should i run it inside each of the IF statements?
Or i was wondering if i could use an if statement which triggers when the button is pressed a second time, which then resets the value of Elite1Total, therefore not totalling up the points cost.

Sorry for the wall of text but im new to this all, this is my 4th week of the course And i know its an extremely basic piece of software but this is where im starting from so any help would be great!

Cheers
 
Thats exactly what i was trying to figure out,
Any ideas, So far ive only worked with integers and Singles (still no idea what that does) so is there something i can change the integer to which makes it change to 0 if the button is pressed again?
Also Another question, Is there a way i can use the integers from one private sub in another button without redeclaring them, i am thinking of putting a button to the side which when pressed clears all the values of the integers inside the private sub but primarily Elite1Total

Thanks
 
I looked into combo boxes but could not find out how to populate them without a data source, so i scrapped that and went with input boxes as im familiar with them.
And to change a private form to public form do i just change the word private at the front to Public?
 
Thanks for the help so far,
Ill be having mine shortly :P
I would rather not re-write the whole thing to use combo boxes as i have already written 80% of the code, just need to finish off a few more categories and eliminate small problems like this.
I have a feeling there is a command you type after declaring Elite1total as an integer, im thinking something like Dim Elite1total As integer = Reset to 0, Or something similar.

Thanks so far though
 
Cheers for the help so far,
But i have added in Elite1total = 0 after the If statements and it still wont reset the value, Also i tried inputting redim elite1total and it gave me a rather complicated error.
I dont suppose you have steam? if so my username is in my sig, Would be a great deal easier then constantly replying to this thread :P

Thanks
 
Cheers for the help,
It does not want to recognise the Replace Then on the last IF statement.

EDIT: Got it working, I jsut removed the If statement starting with replace then and it all seems to be working perfectly, will implement this over all of the other options and see what i can do.

Cheers
 
Last edited:
I deleted that and it is working for Elite choice one, just tried it on elite choice 2 and im yet to get it working.
Does the statement actually do anything? It appears to just open an if statement and then End it?
 
The problem appears to be fixed,
Its just messing up the Army_total now, I cant seem to update it properly now, Looks like thigns are really goind downhill with this.
 
We used Cint at college so im ok with that bit,
What i dont understand is why you are using Armytotaltxt.text in the sum? and where is form_load() located?

Thanks
 
Ok i added a breakpoint, what exactly does it do,
With the army value i have added 2 groups of 10 immortals totalling up to 560 points however in the army total it is only showing me the points for one group, so 280 points.
 
Ok will do that,
Cheers for the help so far but im going to knock it on the head for tonight/Sweeney todd is on.
Will see what i can do to it in college tomorrow when the teachers around and will update this tomorrow night.

Thanks
 
Cheers for the help so far all,
Right i am just trying to use a previoudly declared from a sub in another sub now in order to set it back to 0 when the button is pressed.
I have set both subs i want to use as Public but still it says that the variable has not been declared?

Thanks
 
Me again,
Right now i am using a combo box, however i am trying to give each option a value as i cannot use it as a text value.
For example Autarch is one of the options from the combo box.
If the user was to select Autarch how would i create an IF statement from this, i cannot do IF HQ1 = Autarch as it is not an integer.

Thanks
 
Back
Top Bottom