• Visual Basic Help...
    2 replies, posted
Okay, so I got pretty much zero help with this over at Fast Threads, I dunno what I expected really. Anyway, as posted there: I need to be able to use a variable that I declared in one Sub in another one. Code here: [code]Public Class Form1 Public Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim Roll_1 As Single Roll_1 = Fix((90 - 80 + 1) * Rnd() + 80) End Sub Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged Dim Lead_1, Cha_1, Brn_1, Dex_1, Int_1, Wis_1 As Single If ComboBox1.Text = "Thinker" Then Lead_1 = Roll_1 * 0.1 Cha_1 = Roll_1 * 0.2 Brn_1 = 0 Dex_1 = 0 Int_1 = Roll_1 * 0.5 Wis_1 = Roll_1 * 0.2 ElseIf ComboBox1.Text = "Inventor" Then Lead_1 = Roll_1 * 0.2 Cha_1 = Roll_1 * 0.2 Brn_1 = Roll_1 * 0.1 Dex_1 = Roll_1 * 0.1 Int_1 = Roll_1 * 0.3 Wis_1 = Roll_1 * 0.1 ElseIf ComboBox1.Text = "Barbarian" Then Lead_1 = 0 Cha_1 = 0 Brn_1 = Roll_1 * 0.5 Dex_1 = Roll_1 * 0.5 Int_1 = 0 Wis_1 = 0 ElseIf ComboBox1.Text = "Hero" Then Lead_1 = Roll_1 * 0.5 Cha_1 = Roll_1 * 0.3 Brn_1 = Roll_1 * 0.1 Dex_1 = Roll_1 * 0.1 Int_1 = 0 Wis_1 = 0 ElseIf ComboBox1.Text = "Joker" Then Lead_1 = Roll_1 * 0.1 Cha_1 = Roll_1 * 0.3 Brn_1 = 0 Dex_1 = Roll_1 * 0.3 Int_1 = Roll_1 * 0.1 Wis_1 = Roll_1 * 0.2 ElseIf ComboBox1.Text = "Watchman" Then Lead_1 = Roll_1 * 0.3 Cha_1 = Roll_1 * 0.3 Brn_1 = Roll_1 * 0.2 Dex_1 = Roll_1 * 0.2 Int_1 = 0 Wis_1 = 0 ElseIf ComboBox1.Text = "Priest" Then Lead_1 = Roll_1 * 0.5 Cha_1 = Roll_1 * 0.1 Brn_1 = 0 Dex_1 = 0 Int_1 = Roll_1 * 0.2 Wis_1 = Roll_1 * 0.2 ElseIf ComboBox1.Text = "Healer" Then Lead_1 = Roll_1 * 0.2 Cha_1 = Roll_1 * 0.3 Brn_1 = 0 Dex_1 = Roll_1 * 0.1 Int_1 = Roll_1 * 0.3 Wis_1 = Roll_1 * 0.1 ElseIf ComboBox1.Text = "Scholar" Then Lead_1 = 0 Cha_1 = 0 Brn_1 = 0 Dex_1 = 0 Int_1 = Roll_1 * 0.5 Wis_1 = Roll_1 * 0.5 ElseIf ComboBox1.Text = "Warrior" Then Lead_1 = Roll_1 * 0.2 Cha_1 = 0 Brn_1 = Roll_1 * 0.3 Dex_1 = Roll_1 * 0.3 Int_1 = Roll_1 * 0.2 Wis_1 = 0 ElseIf ComboBox1.Text = "Governor" Then Lead_1 = Roll_1 * 0.3 Cha_1 = Roll_1 * 0.2 Brn_1 = 0 Dex_1 = 0 Int_1 = Roll_1 * 0.3 Wis_1 = Roll_1 * 0.2 ElseIf ComboBox1.Text = "Spy" Then Lead_1 = Roll_1 * 0.3 Cha_1 = Roll_1 * 0.5 Brn_1 = 0 Dex_1 = 0 Int_1 = Roll_1 * 0.2 Wis_1 = 0 ElseIf ComboBox1.Text = "Merchant" Then Lead_1 = 0 Cha_1 = Roll_1 * 0.3 Brn_1 = Roll_1 * 0.2 Dex_1 = Roll_1 * 0.1 Int_1 = Roll_1 * 0.2 Wis_1 = Roll_1 * 0.2 ElseIf ComboBox1.Text = "Assassin" Then Lead_1 = 0 Cha_1 = Roll_1 * 0.3 Brn_1 = Roll_1 * 0.1 Dex_1 = Roll_1 * 0.3 Int_1 = Roll_1 * 0.3 Wis_1 = 0 ElseIf ComboBox1.Text = "Hermit" Then Lead_1 = 0 Cha_1 = 0 Brn_1 = Roll_1 * 0.1 Dex_1 = Roll_1 * 0.2 Int_1 = Roll_1 * 0.2 Wis_1 = Roll_1 * 0.5 ElseIf ComboBox1.Text = "Philosopher" Then Lead_1 = 0 Cha_1 = Roll_1 * 0.2 Brn_1 = 0 Dex_1 = 0 Int_1 = Roll_1 * 0.3 Wis_1 = Roll_1 * 0.5 ElseIf ComboBox1.Text = "Alchemist" Then Lead_1 = Roll_1 * 0.1 Cha_1 = Roll_1 * 0.1 Brn_1 = Roll_1 * 0.1 Dex_1 = Roll_1 * 0.1 Int_1 = Roll_1 * 0.5 Wis_1 = Roll_1 * 0.1 ElseIf ComboBox1.Text = "Thief" Then Lead_1 = 0 Cha_1 = Roll_1 * 0.1 Brn_1 = Roll_1 * 0.2 Dex_1 = Roll_1 * 0.5 Int_1 = Roll_1 * 0.2 Wis_1 = 0 ElseIf ComboBox1.Text = "Horseman" Then Lead_1 = Roll_1 * 0.2 Cha_1 = Roll_1 * 0.2 Brn_1 = Roll_1 * 0.2 Dex_1 = Roll_1 * 0.2 Int_1 = Roll_1 * 0.2 Wis_1 = 0 End If End Sub[/code] You can pretty much ignore all that copypasta stuff, it's just that Roll_1 variable at the top I need to carry over to the second bit.
[QUOTE=Applecrap;16011098]Okay, so I got pretty much zero help with this over at Fast Threads, I dunno what I expected really. Anyway, as posted there: I need to be able to use a variable that I declared in one Sub in another one. Code here: [code]Public Class Form1 Public Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim Roll_1 As Single Roll_1 = Fix((90 - 80 + 1) * Rnd() + 80) End Sub Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged Dim Lead_1, Cha_1, Brn_1, Dex_1, Int_1, Wis_1 As Single If ComboBox1.Text = "Thinker" Then Lead_1 = Roll_1 * 0.1 Cha_1 = Roll_1 * 0.2 Brn_1 = 0 Dex_1 = 0 Int_1 = Roll_1 * 0.5 Wis_1 = Roll_1 * 0.2 ElseIf ComboBox1.Text = "Inventor" Then Lead_1 = Roll_1 * 0.2 Cha_1 = Roll_1 * 0.2 Brn_1 = Roll_1 * 0.1 Dex_1 = Roll_1 * 0.1 Int_1 = Roll_1 * 0.3 Wis_1 = Roll_1 * 0.1 ElseIf ComboBox1.Text = "Barbarian" Then Lead_1 = 0 Cha_1 = 0 Brn_1 = Roll_1 * 0.5 Dex_1 = Roll_1 * 0.5 Int_1 = 0 Wis_1 = 0 ElseIf ComboBox1.Text = "Hero" Then Lead_1 = Roll_1 * 0.5 Cha_1 = Roll_1 * 0.3 Brn_1 = Roll_1 * 0.1 Dex_1 = Roll_1 * 0.1 Int_1 = 0 Wis_1 = 0 ElseIf ComboBox1.Text = "Joker" Then Lead_1 = Roll_1 * 0.1 Cha_1 = Roll_1 * 0.3 Brn_1 = 0 Dex_1 = Roll_1 * 0.3 Int_1 = Roll_1 * 0.1 Wis_1 = Roll_1 * 0.2 ElseIf ComboBox1.Text = "Watchman" Then Lead_1 = Roll_1 * 0.3 Cha_1 = Roll_1 * 0.3 Brn_1 = Roll_1 * 0.2 Dex_1 = Roll_1 * 0.2 Int_1 = 0 Wis_1 = 0 ElseIf ComboBox1.Text = "Priest" Then Lead_1 = Roll_1 * 0.5 Cha_1 = Roll_1 * 0.1 Brn_1 = 0 Dex_1 = 0 Int_1 = Roll_1 * 0.2 Wis_1 = Roll_1 * 0.2 ElseIf ComboBox1.Text = "Healer" Then Lead_1 = Roll_1 * 0.2 Cha_1 = Roll_1 * 0.3 Brn_1 = 0 Dex_1 = Roll_1 * 0.1 Int_1 = Roll_1 * 0.3 Wis_1 = Roll_1 * 0.1 ElseIf ComboBox1.Text = "Scholar" Then Lead_1 = 0 Cha_1 = 0 Brn_1 = 0 Dex_1 = 0 Int_1 = Roll_1 * 0.5 Wis_1 = Roll_1 * 0.5 ElseIf ComboBox1.Text = "Warrior" Then Lead_1 = Roll_1 * 0.2 Cha_1 = 0 Brn_1 = Roll_1 * 0.3 Dex_1 = Roll_1 * 0.3 Int_1 = Roll_1 * 0.2 Wis_1 = 0 ElseIf ComboBox1.Text = "Governor" Then Lead_1 = Roll_1 * 0.3 Cha_1 = Roll_1 * 0.2 Brn_1 = 0 Dex_1 = 0 Int_1 = Roll_1 * 0.3 Wis_1 = Roll_1 * 0.2 ElseIf ComboBox1.Text = "Spy" Then Lead_1 = Roll_1 * 0.3 Cha_1 = Roll_1 * 0.5 Brn_1 = 0 Dex_1 = 0 Int_1 = Roll_1 * 0.2 Wis_1 = 0 ElseIf ComboBox1.Text = "Merchant" Then Lead_1 = 0 Cha_1 = Roll_1 * 0.3 Brn_1 = Roll_1 * 0.2 Dex_1 = Roll_1 * 0.1 Int_1 = Roll_1 * 0.2 Wis_1 = Roll_1 * 0.2 ElseIf ComboBox1.Text = "Assassin" Then Lead_1 = 0 Cha_1 = Roll_1 * 0.3 Brn_1 = Roll_1 * 0.1 Dex_1 = Roll_1 * 0.3 Int_1 = Roll_1 * 0.3 Wis_1 = 0 ElseIf ComboBox1.Text = "Hermit" Then Lead_1 = 0 Cha_1 = 0 Brn_1 = Roll_1 * 0.1 Dex_1 = Roll_1 * 0.2 Int_1 = Roll_1 * 0.2 Wis_1 = Roll_1 * 0.5 ElseIf ComboBox1.Text = "Philosopher" Then Lead_1 = 0 Cha_1 = Roll_1 * 0.2 Brn_1 = 0 Dex_1 = 0 Int_1 = Roll_1 * 0.3 Wis_1 = Roll_1 * 0.5 ElseIf ComboBox1.Text = "Alchemist" Then Lead_1 = Roll_1 * 0.1 Cha_1 = Roll_1 * 0.1 Brn_1 = Roll_1 * 0.1 Dex_1 = Roll_1 * 0.1 Int_1 = Roll_1 * 0.5 Wis_1 = Roll_1 * 0.1 ElseIf ComboBox1.Text = "Thief" Then Lead_1 = 0 Cha_1 = Roll_1 * 0.1 Brn_1 = Roll_1 * 0.2 Dex_1 = Roll_1 * 0.5 Int_1 = Roll_1 * 0.2 Wis_1 = 0 ElseIf ComboBox1.Text = "Horseman" Then Lead_1 = Roll_1 * 0.2 Cha_1 = Roll_1 * 0.2 Brn_1 = Roll_1 * 0.2 Dex_1 = Roll_1 * 0.2 Int_1 = Roll_1 * 0.2 Wis_1 = 0 End If End Sub[/code] You can pretty much ignore all that copypasta stuff, it's just that Roll_1 variable at the top I need to carry over to the second bit.[/QUOTE] [code] Public Class Form1 Dim Roll_1 As Single Public Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Roll_1 = Fix((90 - 80 + 1) * Rnd() + 80) End Sub Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged Dim Lead_1, Cha_1, Brn_1, Dex_1, Int_1, Wis_1 As Single [...] End Sub [/code] Just move Dim Roll_1 As Single into the class scope. Look up "Variable Scope" for more information.
Hah, I knew it had to be simple! Thank you so much. I may be back soon. ;-; [editline]01:53AM[/editline] Blarg, nevermind, I think I got it now.
Sorry, you need to Log In to post a reply to this thread.