• Welcome to TechPowerUp Forums, Guest! Please check out our forum guidelines for info related to our community.

VB.NET bug driving me nuts.

Joined
Dec 22, 2007
Messages
184 (0.03/day)
Location
Central Nebraska
System Name CORSAIR
Processor AMD Phenom 1090T x6 @3.2
Motherboard Gigabyte Ga-78LMT-S2P
Cooling High efficiency dust cooling
Memory 8GB GSkill DDR3 1333
Video Card(s) Sapphire Radeon HD3870 512MB GDDR4 PCI-e toxic
Storage Seagate SV35.3 ST3250310SV 250GB SATAII(Windows 7 Pro x64), 320GB Samsung SATAII(Storage and SuSE)
Display(s) Dell 20" LCD, Dell 17" LCD
Power Supply Antec Cool Blue 650W Modular
Software Windows 7 Professional SP1, Visual Studio 2010 Ultimate
I've been tryign to debug this for a week and have been unsuccessful finding the issue.

When runnign through the code below, the second function can never return the TargetID # from the database. I think there is something wrong with my input send to the function.

Code:
 Function recv() As String
        Dim data(4096) As Byte
        sock.Receive(data, 4096, SocketFlags.None)
        Dim mail As String = System.Text.ASCIIEncoding.UTF8.GetString(data)
        Dim mailpeices As Array = mail.Split(" ")
        If mail.Contains(" ") Then
            If mail.Substring(0, 4) = "PING" Then
                Dim pserv As String = mail.Substring(mail.IndexOf(":"), mail.Length - mail.IndexOf(":"))
                pserv = pserv.TrimEnd(Chr(0))
                mail = "PING from " & pserv & vbNewLine & "PONG to " & pserv
                send("PONG " & pserv)
            ElseIf mail.Contains("PRIVMSG") Then
                Dim tmparr() As String = Nothing
                Dim rnick As String
                Dim rmsg As String
                mail = mail.Remove(0, 1)
                tmparr = mail.Split("!")
                rnick = tmparr(0)
                tmparr = mail.Split(":")
                rmsg = tmparr(1)
                mail = "msg: " & rnick & ">" & rmsg

                'command identifier
                If rmsg.StartsWith("!RXGB ") Then

                    ' commands()
                    If rmsg.StartsWith("!RoXTELL join") Then
                        send("JOIN " & Channel)

                    ElseIf rmsg.StartsWith("!RXGB test2") Then
                        send("PRIVMSG " & Channel & " :I LIKE BREAD AND BUTTAAAAA!")

                    ElseIf rmsg.StartsWith("!RXGB test") Then
                        send("PRIVMSG " & rnick & " :Do you like Corn Syrup?")

                    End If
                ElseIf rmsg.StartsWith("!RoXTELL join") Then
                    send("JOIN " & Channel)

                End If


                If rmsg.StartsWith("!RoXATTACK ") Then
                    Dim MessageParts() As String = rmsg.Split(Chr(32))
                    Dim MessageArray As Array = rmsg.Split(" ")

                    Dim Target As String = MessageParts(2) ' need proper case
                    Target = Target.Trim(" ")
                    Dim STAT_PLAYER_Attack As Integer
                    Dim STAT_TARGET_Defense As Integer
                    ' Dim STAT_TARGET_HP As Integer

                    Select Case MessageParts(1).ToLower
                        Case "standard"

                            'grab PLAYER character ID
                            Dim CharacterID As Integer = GrabCharacterID(rnick)

                            Dim ReadStatPlayerAttackConnection As MySqlConnection = New MySqlConnection(mySQL_Server_String)
                            Dim ReadStatPlayerAttackString As String = "select Attack from Stats_" & rnick & " where ID = '" & CharacterID & "';"
                            Dim ReadStatPlayerAttackCommand As New MySqlCommand(ReadStatPlayerAttackString, ReadStatPlayerAttackConnection)
                            Dim ReadStatPlayerAttackReader As MySqlDataReader
                            Dim ReadStatPlayerAttackResult As Integer

                            Try

                                ReadStatPlayerAttackConnection.Open()
                                ReadStatPlayerAttackReader = ReadStatPlayerAttackCommand.ExecuteReader()
                                ReadStatPlayerAttackReader.Read()
                                ReadStatPlayerAttackResult = ReadStatPlayerAttackReader.GetInt16(0)
                                STAT_PLAYER_Attack = ReadStatPlayerAttackResult

                                cout.WriteLine(STAT_PLAYER_Attack)

                                ReadStatPlayerAttackReader.Close()
                                ReadStatPlayerAttackConnection.Close()
                                ReadStatPlayerAttackReader.Dispose()
                                ReadStatPlayerAttackConnection.Dispose()


                                'grab TARGET character ID
                                Dim TargetID As Integer = GrabTargetID(Target)
                                cout.WriteLine(Target & ":" & TargetID.ToString)

                                send("PRIVMSG " & Channel & " :Target is " & Target & ".  Target ID is " & TargetID.ToString)

                                Try

                                    Dim ReadStatTargetDefenseConnection As MySqlConnection = New MySqlConnection(mySQL_Server_String)
                                    Dim ReadStatTargetDefenseString As String = "select Defense from Stats_" & Target & " where ID = '" & TargetID & "';"
                                    Dim ReadStatTargetDefenseCommand As New MySqlCommand(ReadStatTargetDefenseString, ReadStatTargetDefenseConnection)
                                    Dim ReadStatTargetDefenseReader As MySqlDataReader
                                    Dim ReadStatTargetDefenseResult As Integer

                                    ReadStatTargetDefenseConnection.Open()
                                    ReadStatTargetDefenseReader = ReadStatTargetDefenseCommand.ExecuteReader()
                                    ReadStatTargetDefenseReader.Read()
                                    ReadStatTargetDefenseResult = ReadStatTargetDefenseReader.GetInt16(0)
                                    STAT_TARGET_Defense = ReadStatTargetDefenseResult

                                    cout.WriteLine(STAT_TARGET_Defense)

                                    ReadStatTargetDefenseReader.Close()
                                    ReadStatTargetDefenseConnection.Close()
                                    ReadStatTargetDefenseReader.Dispose()
                                    ReadStatTargetDefenseConnection.Dispose()


                                    '   Try
                                    '
                                    '  Dim AttackDamage As Integer
                                    ' AttackDamage = STAT_PLAYER_Attack - STAT_TARGET_Defense

                                    ' Dim STAT_TARGET_NewHP As Integer
                                    ' STAT_TARGET_NewHP = STAT_TARGET_HP - AttackDamage

                                    '  Dim writeline As String = rnick & " attacks " & Target & " for " & AttackDamage.ToString & " points of damage."
                                    '   writeline = writeline.TrimEnd(Chr(0))
                                    '   writeline = writeline.Remove(writeline.LastIndexOf(vbLf), 1)
                                    '   writeline = writeline.Remove(writeline.LastIndexOf(vbCr), 1)
                                    '   cout.WriteLine(writeline)


                                    '    Catch
                                    '    Dim writeline As String = "Error calculating damage"
                                    '     writeline = writeline.TrimEnd(Chr(0))
                                    '   writeline = writeline.Remove(writeline.LastIndexOf(vbLf), 1)
                                    '     writeline = writeline.Remove(writeline.LastIndexOf(vbCr), 1)
                                    '     cout.WriteLine(writeline)
                                    '  End Try


                                Catch
                                    Dim writeline As String = "Error grabbing target ID or Defense Stat"
                                    cout.WriteLine(writeline)
                                End Try
                            Catch
                                Dim writeline As String = "Error grabbing player attack stat"
                                cout.WriteLine(writeline)
                            End Try

                    End Select
                    mail = ""
                End If




            ElseIf mail.Contains("IDENTIFY") Then
                send("PRIVMSG nickserv :identify R@sM8V0Us")
            ElseIf mail.Contains("recognized") Then
                send("JOIN " & Channel)
            ElseIf mail.Contains("JOIN") Then
                If mailpeices(1) = "JOIN" Then
                    send("PRIVMSG " & Channel & " " & mailpeices(0) & " joined " & Channel & ".")
                Else
                End If

            ElseIf mail.Contains(":") Then

            End If
        End If
        Try
            mail = mail.TrimEnd(Chr(0))
            mail = mail.Remove(mail.LastIndexOf(vbLf), 1)
            mail = mail.Remove(mail.LastIndexOf(vbCr), 1)
            Return mail
        Catch

        End Try

    End Function

    Public Function GrabCharacterID(ByVal ProperName As String)
        'Grab the newly created character's character # from the index

        Dim GrabCharacterIDConnection As MySqlConnection = New MySqlConnection(mySQL_Server_String)
        Dim GrabCharacterIDString As String = "select ID from Characters where Name = '" & ProperName & "';"
        Dim GrabCharacterIDCommand As New MySqlCommand(GrabCharacterIDString, GrabCharacterIDConnection)
        Dim GrabCharacterIDReader As MySqlDataReader
        Dim Result As Integer = -1
        Try
            GrabCharacterIDConnection.Open()
            GrabCharacterIDReader = GrabCharacterIDCommand.ExecuteReader()
            GrabCharacterIDReader.Read()
            Result = GrabCharacterIDReader.GetInt16(0)
            Return Result
        Catch e As Exception
            Return Result
        End Try

    End Function

    Public Function GrabTargetID(ByVal TargetName As String)
        'Grab the newly created character's character # from the index
        TargetName = TargetName.Trim(" ")
        Dim GrabCharacterIDConnection As MySqlConnection = New MySqlConnection(mySQL_Server_String2)
        Dim GrabCharacterIDString As String = "select ID from Characters where Name = '" & TargetName & "';"
        Dim GrabCharacterIDCommand As New MySqlCommand(GrabCharacterIDString, GrabCharacterIDConnection)
        Dim GrabCharacterIDReader As MySqlDataReader
        Dim Result As Integer = -1
        Try
            GrabCharacterIDConnection.Open()
            GrabCharacterIDReader = GrabCharacterIDCommand.ExecuteReader()
            GrabCharacterIDReader.Read()
            Result = GrabCharacterIDReader.GetInt16(0)
            Return Result
        Catch e As Exception
            Return Result
        End Try

    End Function

As I say - I think there is something with the input sent to the function, as the following line:
Code:
send("PRIVMSG " & Channel & " :Target is " & Target & ".  Target ID is " & TargetID.ToString)
only ever returns "Target is <target>" and cuts the rest off afterwards.

making a gui version of this resulkts in the same thing.

The CharacterID (From function GrabCharacterID) is returned properly, but not the TargetID (from fucntion GrabTaretID, which is a copy/paste of GrabCharacterID). I think I have it narrowed down the the name I am sending to use to retrieve the ID. Somehow Im not stripping off a linefeed or carriage return or something properly.

Any ideas? I'm really at a loss here. :banghead:
 
Last edited:
Joined
Dec 22, 2007
Messages
184 (0.03/day)
Location
Central Nebraska
System Name CORSAIR
Processor AMD Phenom 1090T x6 @3.2
Motherboard Gigabyte Ga-78LMT-S2P
Cooling High efficiency dust cooling
Memory 8GB GSkill DDR3 1333
Video Card(s) Sapphire Radeon HD3870 512MB GDDR4 PCI-e toxic
Storage Seagate SV35.3 ST3250310SV 250GB SATAII(Windows 7 Pro x64), 320GB Samsung SATAII(Storage and SuSE)
Display(s) Dell 20" LCD, Dell 17" LCD
Power Supply Antec Cool Blue 650W Modular
Software Windows 7 Professional SP1, Visual Studio 2010 Ultimate
running the console application... I get a bunch of blank lines after the targetname when printing it to the console.
 
Joined
Dec 22, 2007
Messages
184 (0.03/day)
Location
Central Nebraska
System Name CORSAIR
Processor AMD Phenom 1090T x6 @3.2
Motherboard Gigabyte Ga-78LMT-S2P
Cooling High efficiency dust cooling
Memory 8GB GSkill DDR3 1333
Video Card(s) Sapphire Radeon HD3870 512MB GDDR4 PCI-e toxic
Storage Seagate SV35.3 ST3250310SV 250GB SATAII(Windows 7 Pro x64), 320GB Samsung SATAII(Storage and SuSE)
Display(s) Dell 20" LCD, Dell 17" LCD
Power Supply Antec Cool Blue 650W Modular
Software Windows 7 Professional SP1, Visual Studio 2010 Ultimate
No one has any ideas? :(
 

FordGT90Concept

"I go fast!1!11!1!"
Joined
Oct 13, 2008
Messages
26,259 (4.63/day)
Location
IA, USA
System Name BY-2021
Processor AMD Ryzen 7 5800X (65w eco profile)
Motherboard MSI B550 Gaming Plus
Cooling Scythe Mugen (rev 5)
Memory 2 x Kingston HyperX DDR4-3200 32 GiB
Video Card(s) AMD Radeon RX 7900 XT
Storage Samsung 980 Pro, Seagate Exos X20 TB 7200 RPM
Display(s) Nixeus NX-EDG274K (3840x2160@144 DP) + Samsung SyncMaster 906BW (1440x900@60 HDMI-DVI)
Case Coolermaster HAF 932 w/ USB 3.0 5.25" bay + USB 3.2 (A+C) 3.5" bay
Audio Device(s) Realtek ALC1150, Micca OriGen+
Power Supply Enermax Platimax 850w
Mouse Nixeus REVEL-X
Keyboard Tesoro Excalibur
Software Windows 10 Home 64-bit
Benchmark Scores Faster than the tortoise; slower than the hare.
What is "sock" definied as? When you put in breakpoints, which line fails? The "send" line? Have you broke at Target and TargetID to confirm they have valid data?
 
Joined
Dec 22, 2007
Messages
184 (0.03/day)
Location
Central Nebraska
System Name CORSAIR
Processor AMD Phenom 1090T x6 @3.2
Motherboard Gigabyte Ga-78LMT-S2P
Cooling High efficiency dust cooling
Memory 8GB GSkill DDR3 1333
Video Card(s) Sapphire Radeon HD3870 512MB GDDR4 PCI-e toxic
Storage Seagate SV35.3 ST3250310SV 250GB SATAII(Windows 7 Pro x64), 320GB Samsung SATAII(Storage and SuSE)
Display(s) Dell 20" LCD, Dell 17" LCD
Power Supply Antec Cool Blue 650W Modular
Software Windows 7 Professional SP1, Visual Studio 2010 Ultimate
Solution

My issue was:
I had my received byte defined as 4096.
So if a message was received that was less than this amount of data, white space was added to make it 4096.

Because I was breaking strings down into arrays based on spaces, the last item in the array contained the text + the whitespace. ran a for loop which ran through each character and added it together into a new version of the string, but only IF the character showed up as a letter.

instead of sending
"MyName"

it would search for

"MyName



"

Works great now. Thanks for the reply Ford!
 

FordGT90Concept

"I go fast!1!11!1!"
Joined
Oct 13, 2008
Messages
26,259 (4.63/day)
Location
IA, USA
System Name BY-2021
Processor AMD Ryzen 7 5800X (65w eco profile)
Motherboard MSI B550 Gaming Plus
Cooling Scythe Mugen (rev 5)
Memory 2 x Kingston HyperX DDR4-3200 32 GiB
Video Card(s) AMD Radeon RX 7900 XT
Storage Samsung 980 Pro, Seagate Exos X20 TB 7200 RPM
Display(s) Nixeus NX-EDG274K (3840x2160@144 DP) + Samsung SyncMaster 906BW (1440x900@60 HDMI-DVI)
Case Coolermaster HAF 932 w/ USB 3.0 5.25" bay + USB 3.2 (A+C) 3.5" bay
Audio Device(s) Realtek ALC1150, Micca OriGen+
Power Supply Enermax Platimax 850w
Mouse Nixeus REVEL-X
Keyboard Tesoro Excalibur
Software Windows 10 Home 64-bit
Benchmark Scores Faster than the tortoise; slower than the hare.
FYI, you can trim that by doing string.Trim(Chr(0)) in VB or string.Trim('\0') in C#. Good programming practice is to size the packets to its contents, however.
 
Top