index out of range?

cpgames

Member
Joined
Sep 14, 2011
Messages
14
Programming Experience
Beginner
hello i am codding a program and I get an error index out of range exception was unhandeled
my code is



[XCODE]
Public Class Form1 Dim OS() As String
Dim UserName() As String

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
OS = My.Computer.Info_OSFullName.Split("")
UserName = My.User.Name.Split("\")
TextBox1.Text = OS(2)
TextBox2.Text = UserName(1)




If OS(2) = "XP" Then TextBox3.Text = "C:\Documents and Settings\" & UserName(1) & "\Application Data\.minecraft\bin\minecraft.jar" Else
TextBox3.Text = "C:\Users\" & UserName(1) & "\AppData\Roaming\.minecraft\bin\minecraft.jar"


End Sub

End Class

[/XCODE]


and it has an error in the line of code

[XCODE]
TextBox1.Text = OS(2)
[/XCODE]


please help

thanks charlie
 
Turn on Option Strict, and change the code to: .OSFullName.Split(" "c)
 
Hi i had a quick look while reading peeps post's and the reason you get this is your trying to use an "Array" with out establishing one for the "OS", i'm sure you need to make you code like so

OS() <--these brackets = My.Computer.Info_OSFullName.Split("")

this is why i would say the index is out of bounds as in your segment this pice is not an array, as your trying to call

OS <--- Needs Array = My.Computer.Info_OSFullName.Split("")
als when using "Arrays" it's better to give them a value, Array Value's allways stare from 0 to num meaning if you wanted to do a list box with 3 arrays adding to it then the array would look like dim MyValue(2) as String/Integer <- depending what you need, and the Array Would be presented like 0, 1, 2.
 
Back
Top