Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > Game Programming > Combo Box's


Reply
 
Thread Tools Display Modes
  #1  
Old 06-09-2004, 07:53 AM
algebrapro18's Avatar
algebrapro18 algebrapro18 is offline
Regular
 
Join Date: Dec 2003
Location: Platteville, Wisconsin
Posts: 61
Default Combo Box's


I have 4 combo boxes and I added things to them using the .additem method but none of the things I have added show up when I run the program. Here is the code I have.


Dim intBattle As Integer
Dim intWeaponPower As Integer
Dim intMonAttack As Integer
Dim intPower As Integer


cboAttack.AddItem "Attack"
cboAttack.AddItem "Use Magic"
cboAttack.AddItem "Use Item"
cboAttack.AddItem "Summon"
cboAttack.AddItem "Run Away"

If cboAttack.Text = "Attack" Then

intMonster = RanGen(1, 5)
intBattle = RanGen(1, 4)
intMonAttack = RanGen(1, 2)
strWeapon = "Fist"
strArmor = "Clothing"
intWeaponPower = 1
intExp = 0
intLevel = 1

Select Case intMonster
Case Is = 1
strMonster = "Wild Cat"
intMonHP = 10
intPower = 2
Case Is = 2
strMonster = "Wild Dog"
intMonHP = 20
intPower = 2
Case Is = 3
strMonster = "Lion"
intMonHP = 30
intPower = 10
Case Is = 4
strMonster = "Tiger"
intMonHP = 40
intPower = 15
Case Is = 5
strMonster = "Dragon"
intMonHP = 50
intPower = 18
End Select

Form1.txtOutput.Text = Form1.txtOutput.Text & "You have been attacked by a " & strMonster


Form1.txtOutput.Text = Form1.txtOutput.Text & " It has " & intMonHP & " Hit Points." & vbNewLine

If intBattle = 1 Then
Select Case intMonster
Case 1
Form1.txtOutput.Text = Form1.txtOutput.Text & "You have hit the " & strMonster & " for " & intWeaponPower & " Hit Points." & vbNewLine
Case 2
Form1.txtOutput.Text = Form1.txtOutput.Text & "You have hit the " & strMonster & " for " & intWeaponPower & " Hit Points." & vbNewLine
Case 3
Form1.txtOutput.Text = Form1.txtOutput.Text & "You have hit the Lion for " & intWeaponPower & " Hit Points." & vbNewLine
Case 4
Form1.txtOutput.Text = Form1.txtOutput.Text & "You have hit the Tiger for " & intWeaponPower & " Hit Points." & vbNewLine
Case 5
Form1.txtOutput.Text = Form1.txtOutput.Text & "You have hit the Lion for " & intWeaponPower & " Hit Points." & vbNewLine
End Select

intBattle = RanGen(3, 4)
intMonHP = intMonHP - intWeaponPower
Form1.txtOutput.Text = Form1.txtOutput.Text & "The monster has " & intMonHP & " Hit Points Left" & vbNewLine

ElseIf intBattle = 2 Then
Select Case intMonster
Case 1
Form1.txtOutput.Text = Form1.txtOutput.Text & "You have missed the Wild Cat and it is preparing to attack you!" & vbNewLine
Case 2
Form1.txtOutput.Text = Form1.txtOutput.Text & "You have missed the Wild Dog and it is preparing to attck you!" & vbNewLine
Case 3
Form1.txtOutput.Text = Form1.txtOutput.Text & "You have missed the Lion and it is preparing to attack you!" & vbNewLine
Case 4
Form1.txtOutput.Text = Form1.txtOutput.Text & "You have missed the Tiger and it is preparing to attack you!" & vbNewLine
Case 5
Form1.txtOutput.Text = Form1.txtOutput.Text & "You have missed the Dragon and it is preparing to attack you!" & vbNewLine
End Select

intBattle = RanGen(3, 4)

ElseIf intBattle = 3 Then
Select Case intMonster
Case 1
Form1.txtOutput.Text = Form1.txtOutput.Text & "The Wild Cat missed you! " & vbNewLine & "Prepare to attack it again!" & vbNewLine
Case 2
Form1.txtOutput.Text = Form1.txtOutput.Text & "The Wild Dog missed you! " & vbNewLine & "Prepare to attack it again!" & vbNewLine
Case 3
Form1.txtOutput.Text = Form1.txtOutput.Text & "The Lion missed you! " & vbNewLine & "Prepare to attack it again!" & vbNewLine
Case 4
Form1.txtOutput.Text = Form1.txtOutput.Text & "The Tiger missed you! " & vbNewLine & "Prepare to attack it again!" & vbNewLine
Case 5
Form1.txtOutput.Text = Form1.txtOutput.Text & "The Dragon missed you! " & vbNewLine & "Prepare to attack it again!" & vbNewLine
End Select
intBattle = RanGen(1, 2)

ElseIf intBattle = 4 Then
Select Case intMonster
Case 1
Form1.txtOutput.Text = Form1.txtOutput.Text & "The Wild Cat hit you for " & intPower & " Hit Points!" & vbNewLine
Case 2
Form1.txtOutput.Text = Form1.txtOutput.Text & "The Wild Dog hit you for " & intPower & " Hit Points!" & vbNewLine
Case 3
Form1.txtOutput.Text = Form1.txtOutput.Text & "The Lion hit you for " & intPower & " Hit Points!" & vbNewLine
Case 4
Form1.txtOutput.Text = Form1.txtOutput.Text & "The Tiger hit you for " & intPower & " Hit Points!" & vbNewLine
Case 5
Form1.txtOutput.Text = Form1.txtOutput.Text & "The Dragon hit you for " & intPower & " Hit Points!" & vbNewLine
End Select
intBattle = RanGen(1, 2)
intHP = intHP - intPower
Form1.txtOutput.Text = Form1.txtOutput.Text & "You have " & intHP & " Hit Points left" & vbNewLine

End If


If intMonHP <= 0 Then
Select Case intMonster
Case 1
Form1.txtOutput.Text = Form1.txtOutput.Text & "You have killed the Wild Cat and have earned 10 gill!" & vbNewLine
curGold = curGold + 10
intExp = 10
Case 2
Form1.txtOutput.Text = Form1.txtOutput.Text & "You have killed the Wild Dog and have earned 20 gill!" & vbNewLine
curGold = curGold + 20
intExp = 20
Case 3
Form1.txtOutput.Text = Form1.txtOutput.Text & "You have killed the Lion and have earned 30 gill!" & vbNewLine
curGold = curGold + 30
intExp = 30
Case 4
Form1.txtOutput.Text = Form1.txtOutput.Text & "You have killed the Tiger and have earned 40 gill!" & vbNewLine
curGold = curGold + 40
intExp = 40
Case 5
Form1.txtOutput.Text = Form1.txtOutput.Text & "You have killed the Dragon and have earned 50 gill!" & vbNewLine
curGold = curGold + 50
intExp = 50
End Select
fraMisc.Enabled = True
End If

If intHP <= 0 Then
Form1.txtOutput.Text = Form1.txtOutput.Text & "You have been defeated by the " & strMonster & "." & vbNewLine & "GAME OVER!!!" & vbNewLine
fraBattle.Enabled = False
fraMisc.Enabled = False
End If

ElseIf cboAttack.Text = "Use Magic" Then
cboMagic.Visible = True
ElseIf cboAttack.Text = "Use Item" Then
cboItem.Visible = True
ElseIf cboAttack.Text = "Summon" Then
cboSummon.Visible = True
Else
optRunAway.Enabled = True
End If




End Sub

Private Sub cboMagic_Change()
cboMagic.AddItem "Fire"
cboMagic.AddItem "Ice"


End Sub

Private Sub optRunAway_Click()
Dim run As Integer

run = RanGen(1, 2)

If run = 1 Then
Form1.txtOutput.Text = Form1.txtOutput.Text & "You attempt to run away from battle has failed." & vbNewLine & " Please select what you want to do next."
Else
Form1.txtOutput.Text = Form1.txtOutput.Text & "You have successfully ran away from battle." & vbNewLine & " You have " & intHP & " hit points left." & vbNewLine & "You have " & intMP & " Magic Points Left." & vbNewLine & "Please hit the roam button to continue."
End Sub
Reply With Quote
  #2  
Old 06-09-2004, 10:22 AM
noi_max's Avatar
noi_max noi_max is offline
Still asleep...

Retired Leader
* Expert *
 
Join Date: Nov 2003
Location: IronForge
Posts: 2,694
Default

Hmmm... I don't see anything wrong with the additem method in your code. To make sure I wasn't missing something I added it to the Form Load event in a new project for testing, and it worked just peachy.

Code:
Private Sub Form_Load() cboAttack.AddItem "Attack" cboAttack.AddItem "Use Magic" cboAttack.AddItem "Use Item" cboAttack.AddItem "Summon" cboAttack.AddItem "Run Away" End Sub

So it may be down to where it is in the code (I didn't see a procedure header for the stuff you posted) and when the additem method is used.


***EDIT*** also the types of events you choose will make things behave differently. This procedure, for example didn't do anything:

Code:
Private Sub cboMagic_Change() cboMagic.AddItem "Fire" cboMagic.AddItem "Ice" End Sub

Here is an alternate method (probably not the only one)

Code:
Private Sub cboMagic_DropDown() cboMagic.Clear cboMagic.AddItem "Fire" cboMagic.AddItem "Ice" End Sub

When you are in the code window, there are usually two drop down boxes where you can find your object in the left dropdown, and a list of all the events in the right dropdown.

If you have MSDN installed, you can simply click on the control in the form and hit F1. When the help menu comes up, there should be a link to the events for that control.

Hope that helps!


Max.
__________________
~ Jason

Use [vb][/vb] tags when posting code :) || Search the forum and MSDN|| Check out the Posting Guidelines

Last edited by noi_max; 06-09-2004 at 10:32 AM.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->