From: ryguy7272 on 9 Dec 2009 15:02 I am trying to understand some code that I found online. Basically, this will populate a ListBox with random strings. Here is the code: Protected Sub PopulateButton_Click(ByVal sender As Object, _ ByVal e As System.EventArgs) Dim wordLen As Integer Dim NWords As Integer = 9999 Dim rnd As System.Random rnd = New System.Random() Dim rndChar As Char Dim thisWord As String Dim i, j As Integer For i = 0 To NWords wordLen = CInt(rnd.NextDouble * 20 + 1) thisWord = “” For j = 0 To wordLen rndchar = Chr(65 + CInt(rnd.Next, 25)) thisWord = thisWord & rndChar Next ListBox1.Items.Add(thisWord) Next End Sub I can't get this running and I can understand how to resolve the error. Error mssg: Argument 'CharCode' must be with the range of -32768 to 65535 Can someone please explain what is wrong? Thanks! Ryan-- -- Ryan--- If this information was helpful, please indicate this by clicking ''Yes''.
From: Armin Zingler on 9 Dec 2009 15:51 ryguy7272 schrieb: > I am trying to understand some code that I found online. Basically, this will > populate a ListBox with random strings. Here is the code: > > Protected Sub PopulateButton_Click(ByVal sender As Object, _ > ByVal e As System.EventArgs) > Dim wordLen As Integer > Dim NWords As Integer = 9999 > Dim rnd As System.Random > rnd = New System.Random() > Dim rndChar As Char > Dim thisWord As String > Dim i, j As Integer > For i = 0 To NWords > wordLen = CInt(rnd.NextDouble * 20 + 1) > thisWord = “” > For j = 0 To wordLen > rndchar = Chr(65 + CInt(rnd.Next, 25)) > thisWord = thisWord & rndChar > Next > ListBox1.Items.Add(thisWord) > Next > End Sub > > I can't get this running and I can understand how to resolve the error. > Error mssg: > Argument 'CharCode' must be with the range of -32768 to 65535 > > Can someone please explain what is wrong? I can't compile this. There is an error in the line rndchar = Chr(65 + CInt(rnd.Next, 25)) I guess it's meant to be rndChar = Chr(65 + CInt(rnd.Next(25))) Is that right? However, it doesn't produce the error you're getting, so you should post the real code first. -- Armin
From: Sergey Poberezovskiy on 9 Dec 2009 17:33 Ryan, all you have to do is to correct the following line: rndchar = Chr(65 + CInt(rnd.Next, 25)) to become: rndChar = Chr(65 + CInt(rnd.Next(25))) Obviously, the person that provided the code, was just trying to show the concept (without the IDE handy to correct the syntax) Please let me know if you need more information "ryguy7272" wrote: > I am trying to understand some code that I found online. Basically, this will > populate a ListBox with random strings. Here is the code: > > Protected Sub PopulateButton_Click(ByVal sender As Object, _ > ByVal e As System.EventArgs) > Dim wordLen As Integer > Dim NWords As Integer = 9999 > Dim rnd As System.Random > rnd = New System.Random() > Dim rndChar As Char > Dim thisWord As String > Dim i, j As Integer > For i = 0 To NWords > wordLen = CInt(rnd.NextDouble * 20 + 1) > thisWord = “” > For j = 0 To wordLen > rndchar = Chr(65 + CInt(rnd.Next, 25)) > thisWord = thisWord & rndChar > Next > ListBox1.Items.Add(thisWord) > Next > End Sub > > I can't get this running and I can understand how to resolve the error. > Error mssg: > Argument 'CharCode' must be with the range of -32768 to 65535 > > Can someone please explain what is wrong? > > Thanks! > Ryan-- > -- > Ryan--- > If this information was helpful, please indicate this by clicking ''Yes''.
From: ryguy7272 on 9 Dec 2009 18:01 You are absolutely right! That worked. Thanks so much!! Ryan--- -- Ryan--- If this information was helpful, please indicate this by clicking ''Yes''. "Sergey Poberezovskiy" wrote: > Ryan, > > all you have to do is to correct the following line: > rndchar = Chr(65 + CInt(rnd.Next, 25)) > > to become: > rndChar = Chr(65 + CInt(rnd.Next(25))) > > Obviously, the person that provided the code, was just trying to show the > concept (without the IDE handy to correct the syntax) > > Please let me know if you need more information > "ryguy7272" wrote: > > > I am trying to understand some code that I found online. Basically, this will > > populate a ListBox with random strings. Here is the code: > > > > Protected Sub PopulateButton_Click(ByVal sender As Object, _ > > ByVal e As System.EventArgs) > > Dim wordLen As Integer > > Dim NWords As Integer = 9999 > > Dim rnd As System.Random > > rnd = New System.Random() > > Dim rndChar As Char > > Dim thisWord As String > > Dim i, j As Integer > > For i = 0 To NWords > > wordLen = CInt(rnd.NextDouble * 20 + 1) > > thisWord = “” > > For j = 0 To wordLen > > rndchar = Chr(65 + CInt(rnd.Next, 25)) > > thisWord = thisWord & rndChar > > Next > > ListBox1.Items.Add(thisWord) > > Next > > End Sub > > > > I can't get this running and I can understand how to resolve the error. > > Error mssg: > > Argument 'CharCode' must be with the range of -32768 to 65535 > > > > Can someone please explain what is wrong? > > > > Thanks! > > Ryan-- > > -- > > Ryan--- > > If this information was helpful, please indicate this by clicking ''Yes''.
|
Pages: 1 Prev: .NET 2.0, 3.0, 3.5 on Windows Server 2008 64bit Next: Why Won't My Thread Abort |