i got an error >>> Arithmetic operation resulted in an overflow.

please help

thanks in advance

Private randomClass as new Random
 
For i = 0 To CInt(10) - 1
strId &= Mid(strCodes, Int(Len(strCodes) * randomClass.Next() ) + 1, 1)
Next
 
For i = 0 To CInt(4) - 1
strId2 &= Mid(strCodes, Int(Len(strCodes) * randomClass.Next() ) + 1, 1)
Next

What is the data type of strId and strId2 and why r u doing CInt(10) - 1 and
CInt(4) - 1 As 10 and 4 are integer only. you need not to convert explicitly.
you can directly give 0 to 9 and 0 to 3
in which line ur getting the error?

this is the whole code

lstLicense.Items.Clear()
        lstLicense.Enabled = True

        Dim strCodes As String
        Dim strId As String
        Dim strId2 As String
        Dim zz As String
        Dim item As ListViewItem
        Dim random As New Random
        strCodes = strCodes & A
        strCodes = strCodes & B

        Randomize()

        For i = 0 To CLng(5) - 1
            strId &= Mid(strCodes, CLng(Len(strCodes) * randomClass.Next()) + 1, 1)
        Next

        For i = 0 To CLng(5) - 1
            strId2 &= Mid(strCodes, CLng(Len(strCodes) * randomClass.Next()) + 1, 1)
        Next


        txtPartNumber.Text = zz


        For d As Integer = 0 To DataGridView1.Rows.Count - 2


            With item

                item = lstLicense.Items.Add(DataGridView1.Item(2, d).Value.ToString, 0)
                item.SubItems.Add(DataGridView1.Item(3, d).Value.ToString)
                item.SubItems.Add(zz)

            End With
        Next

Edited 5 Years Ago by TIP.Synergy: n/a

There are so many things wrong here.

That is not "the whole code"

You are concatenating A and B to strCodes but we have no idea what A and B are. Because they are not defined anywhere I must assume they are Class or global variables.

You are using variables that have not been initialized

You use zz, strCodes, strId and strId2 without first assigning them values.

You are not consistent in your variable usage

I may be mistaken, but on lines 16 and 20 shouldn't that be "random" instead of "randomClass"?

You are doing unnecessary calculations and type conversions

For i = 0 To CLng(5) - 1

should be rewritten as

For i as integer from 0 to 4

You still aren't telling us what line threw the error

Having said that, random.Next gets you the next random integer. This number can be very large (eg 835349378) and is likely the cause of the error. next.Double gets the next random double between 0.0 and 1.0. Can you tell us what range you are expecting for the random number?

Edited 5 Years Ago by Reverend Jim: n/a

i forget to inlcude this string

Public Const A As String = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    Public Const B As String = "0123456789"

Actually i already reconstruct my code

here

Public Const A As String = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    Public Const B As String = "0123456789"

  Dim strId, strId1, strId2, strId3, strId4, strId5, strId6 As String
        Dim item As ListViewItem


        For io As Integer = 0 To DataGridView1.Rows.Count - 2

            For i As Integer = 0 To 8
                strId1 = A(randomClass.Next(0, A.Length - 1)).ToString()
                strId2 = A(randomClass.Next(0, A.Length - 1)).ToString()
                strId3 = A(randomClass.Next(0, A.Length - 1)).ToString()
                strId4 = B(randomClass.Next(0, B.Length - 1)).ToString()
                strId5 = B(randomClass.Next(0, B.Length - 1)).ToString()
                strId6 = B(randomClass.Next(0, B.Length - 1)).ToString()

                strId = "EMRSN-" & strId1 & strId2 & strId3 & strId4 & strId5 & strId6

            Next

but all i want is to simplify this code...

This article has been dead for over six months. Start a new discussion instead.