Visual Basic - Object reference not set to an instance of an object - vb.net

I'm receiving the following error in VB.Net.
"Object reference not set to an instance of an object"
It highlights "Next" at the end of the For Loop.
Any help would be great.
Imports System.IO
Public Class LoginForm
Dim Username() As String
Dim Password() As String
Dim Index As Integer
Public Function encrypt(ByVal data As String) As String
Dim answer As String = ""
Dim I As Integer
data = RTrim(data)
If Mid(data, 1, 1) <> Chr(0) Then
For I = 1 To Len(data)
answer = answer + Chr(Asc(Mid(data, I, 1)) Xor 23)
' Xor 23 is a simple encription cipher, a string can be
' encrypted or de-encrypted by the value following the Xor
'i.e. "23" '
Next I
End If
encrypt = answer
End Function
Private Sub LoginButton_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles LoginButton.Click
For Each I In Username
If UserNameTextBox.Text = Username(Index) Then
UserAdd.Show()
Me.Hide()
If PasswordTextBox.Text = Password(Index) Then
MessageBox.Show("Correct Password")
Else
MessageBox.Show("Invalid Password, Sorry")
End If
Else : MessageBox.Show("Invalid Username, Sorry")
End If
Next
End Sub
Public Sub ReadUsers()
Dim CurrentFileReader As StreamReader
Dim FileName, Line As String
Dim Delimiter As Char = ","
Dim Feild() As String
Dim Username() As String
Dim Password() As String
Dim Index As Integer
FileName = "C:\Computing\Projects\Login\Users.txt" 'location of
'user file
CurrentFileReader = New StreamReader(FileName)
Do Until CurrentFileReader.EndOfStream
Line = CurrentFileReader.ReadLine
If Line = Nothing Then
Exit Do
End If
ReDim Preserve Username(Index)
ReDim Preserve Password(Index)
Feild = Line.Split(Delimiter)
Username(Index) = encrypt(Feild(0))
Password(Index) = encrypt(Feild(1))
Loop
End Sub
Private Sub LoginForm_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) _
Handles Me.Load
Call ReadUsers()
End Sub
End Class

Try replacing this code:
For Each I In Username
If UserNameTextBox.Text = Username(Index) Then
UserAdd.Show()
Me.Hide()
If PasswordTextBox.Text = Password(Index) Then
MessageBox.Show("Correct Password")
Else
MessageBox.Show("Invalid Password, Sorry")
End If
Else : MessageBox.Show("Invalid Username, Sorry")
End If
Next
with this code:
For Each I In Username
if Username(i) is not null then
If UserNameTextBox.Text = Username(Index) Then
UserAdd.Show()
Me.Hide()
If PasswordTextBox.Text = Password(Index) Then
MessageBox.Show("Correct Password")
Else
MessageBox.Show("Invalid Password, Sorry")
End If
Else : MessageBox.Show("Invalid Username, Sorry")
End If
else
....handle empty string
end if
Next

Which next are yout refering to?
In your second for, define that is I. That may not solve the problem, but this is definitly a better practive.
Is it possible that your data constains a 'null' character (chr(0))?
Mid will return null if it reaches the end of the string , but it doesn't look like this would happen to you.
Nevertheless, you might want to use String.Substring instead of mid. It's a function found with the string object.

I'll take a guess that it's the "For Each I In Username" loop inside LoginButton_Click that's causing you the problem?
I'm guessing at this loop as the type of variable "I" does not appear to be declared, so it would be type Object by default, matching the error "Object reference not set to an instance of an object".

Sub ReadUsers(), uses the locally defined variables for Username, Index and Password. Remove these lines from Sub ReadUsers().
Dim Username() As String
Dim Password() As String
Dim Index As Integer
At your class level.
A. Add this Imports to the top of the file:
Imports System.Collections.Generic
B. Change your String array definitions to List(of String)
Dim Username As List(Of String)
C. Then you no longer need to Redim. Just:
Username.add(encrypt(Feild(0)))
Loop on the count instead of item:
For i as integer = 0 to Username.length - 1
If UserNameTextBox.Text = Username(i) Then
...
Next
And finally, here's your code:
Imports System.IO
Imports System.Collections.Generic
Public Class LoginForm
' At the Class level Dim is equivalent to Private
Private Username As List(Of String)
Private Password As List(Of String)
Private Index As Integer
Public Function encrypt(ByVal data As String) As String
Dim answer As String = ""
Dim I As Integer
data = RTrim(data)
If Mid(data, 1, 1) <> Chr(0) Then
For I = 1 To Len(data)
answer = answer + Chr(Asc(Mid(data, I, 1)) Xor 23)
' Xor 23 is a simple encription cipher, a string can be
' encrypted or de-encrypted by the value following the Xor
'i.e. "23" '
Next I
End If
encrypt = answer
End Function
Private Sub LoginButton_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles LoginButton.Click
For i As Integer = 0 To Username.length - 1
If UserNameTextBox.Text = Username(i) Then
UserAdd.Show()
Me.Hide()
If PasswordTextBox.Text = Password(i) Then
MessageBox.Show("Correct Password")
Else
MessageBox.Show("Invalid Password, Sorry")
End If
Else : MessageBox.Show("Invalid Username, Sorry")
End If
Next
End Sub
Public Sub ReadUsers()
Dim CurrentFileReader As StreamReader
Dim FileName, Line As String
Dim Delimiter As Char = ","
Dim Feild() As String
FileName = "C:\Computing\Projects\Login\Users.txt" 'location of
'user file
CurrentFileReader = New StreamReader(FileName)
Do Until CurrentFileReader.EndOfStream
Line = CurrentFileReader.ReadLine
If Line = Nothing Then
Exit Do
End If
Feild = Line.Split(Delimiter)
Username.Add(encrypt(Feild(0)))
Password.add(encrypt(Feild(1)))
Loop
End Sub
Private Sub LoginForm_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) _
Handles Me.Load
Call ReadUsers()
End Sub
End Class

Related

I am looking to use textfiles to validate a username and password login

I am looking to use textfiles to validate a username and password in VB.NET.
I have the username validated but I can not validate the passsword and anything entered in txtpassowrd.text will result in a login.
The code I used is this:
Imports System.IO
Public Class frmReceptionist
Function IsInFile(ByVal person As String) As Boolean
If File.Exists("receptionistUser.txt") And File.Exists("receptionistPassword.txt") Then
Dim sr As StreamReader = File.OpenText("receptionistUser.txt")
Dim individual As String
Do Until sr.EndOfStream
individual = sr.ReadLine
If individual = person Then
sr.Close()
Return True
End If
Loop
sr.Close()
End If
Return False
End Function
Private Sub btnConfirm_Click(sender As Object, e As EventArgs) Handles btnConfirm.Click
'Determine if a person is in the file
Dim person As String = txtUsername.Text
If person <> "" Then
If IsInFile(person) Then
MessageBox.Show(person & " Welcome Receptionist", "Bia Duitse")
Me.Hide()
frmBiaDuitse.Show()
Else
MessageBox.Show(person & " Incorrect Login", "No")
End If
Else
MessageBox.Show("You must enter Details", "Information")
End If
txtUsername.Clear()
txtUsername.Focus()
End Sub
Private Sub btnCancel_Click(sender As Object, e As EventArgs) Handles btnCancel.Click
Me.Hide()
frmSelectJob.Show()
End Sub
End Class
This is definitely not the way you should be doing this.
For learning purposes, you could load up your files into a Dictionary() like this:
Private Credentials As Dictionary(Of String, String)
Private Sub LoadCredentials()
If IsNothing(Credentials) Then
Credentials = New Dictionary(Of String, String)()
If File.Exists("receptionistUser.txt") And File.Exists("receptionistPassword.txt") Then
Dim users() As String = File.ReadAllLines("receptionistUser.txt")
Dim passwords() As String = File.ReadAllLines("receptionistPassword.txt")
If users.Length = passwords.Length Then
For i As Integer = 0 To users.Length - 1
Credentials.Add(users(i), passwords(i))
Next
End If
End If
End If
End Sub
Function IsInFile(ByVal person As String) As Boolean
LoadCredentials()
If Not IsNothing(Credentials) Then
Return Credentials.ContainsKey(person)
End If
Return False
End Function
Function Checkpassword(ByVal person As String, ByVal password As String) As Boolean
LoadCredentials()
If Not IsNothing(Credentials) Then
Return Credentials.ContainsKey(person) AndAlso password = Credentials(person)
End If
Return False
End Function

Get IP Addresses of 6 devices using MAC addresses using VB.NET

How do I modify my code to populate a listbox of IP addresses if I know 6 devices MAC addresses?
I am using VB.net to show me my current IP and MAC address but I want to change it to add to a ListBox to show 6 devices on the same network using their MAC addresses. Since we cannot modify the DHCP server, we just want a simple way to show each device's IP address using their known Mac addresses. I will add the MAC addresses in code. but Just want to have the listbox populate on startup of the app.
Existing Code:
Imports System.Net
Imports System.Runtime.InteropServices
Imports System.ComponentModel
Imports System.IO
Imports System.Net.NetworkInformation
Public Class Form1
Private Sub Form1_MouseClick(sender As Object, e As MouseEventArgs) Handles Me.MouseClick
Dim mac As String
mac = GetMacAddress()
Label1.Text = mac
End Sub
Function GetMacAddress()
Dim nics() As NetworkInterface = NetworkInterface.GetAllNetworkInterfaces()
Return nics(0).GetPhysicalAddress.ToString
End Function
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Me.Close()
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
GetIPv4Address()
End Sub
Private Function GetIPv4Address() As String
GetIPv4Address = String.Empty
Dim strHostName As String = System.Net.Dns.GetHostName()
Dim iphe As System.Net.IPHostEntry = System.Net.Dns.GetHostEntry(strHostName)
For Each ipheal As System.Net.IPAddress In iphe.AddressList
If ipheal.AddressFamily = System.Net.Sockets.AddressFamily.InterNetwork Then
GetIPv4Address = ipheal.ToString()
Label2.Text = "IP Address: " & ipheal.ToString
End If
Next
End Function
End Class
Thanks in advance!
Updated Answer - After some more digging, I found untweaked version of the code below here and tweaked it a bit.
What you end up with is a list of IpInfo structures. Each of these objects has the self-explanatory properties of IpAddress, MacAddress and HostName. You can iterate through the list and IP addresses the matching mac addresses to your listbox.
You may need to tweak the Thread.Sleep interval to make sure that you get all the results, but I hope this new answer sorts you out.
If it does, I would suggest removing the comments about the code not working so that they don't confuse others looking at this answer.
Imports System.Net
Imports System.Net.NetworkInformation
Imports System.Net.Sockets
Public Class Form1
Structure IpInfo
Dim IpAddress As String
Dim HostName As String
Dim MacAddress As String
End Structure
Dim connectedIPAddresses As New List(Of IpInfo)
Private Shared Function NetworkGateway() As String
Dim ip As String = Nothing
For Each f As NetworkInterface In NetworkInterface.GetAllNetworkInterfaces()
If f.OperationalStatus = OperationalStatus.Up Then
For Each d As GatewayIPAddressInformation In f.GetIPProperties().GatewayAddresses
ip = d.Address.ToString()
Next
End If
Next
Return ip
End Function
Public Sub Ping_all()
Dim gate_ip As String = NetworkGateway()
Dim array As String() = gate_ip.Split("."c)
For i As Integer = 2 To 255
Dim ping_var As String = array(0) & "." & array(1) & "." & array(2) & "." & i.ToString
Ping(ping_var, 1, 1000)
Next
Task.WhenAll(taskList)
End Sub
Dim taskList As New List(Of Task)
Public Sub Ping(ByVal host As String, ByVal attempts As Integer, ByVal timeout As Integer)
For i As Integer = 0 To attempts - 1
taskList.Add(Task.Run(Sub()
Try
Dim ping As System.Net.NetworkInformation.Ping = New System.Net.NetworkInformation.Ping()
AddHandler ping.PingCompleted, AddressOf PingCompleted
ping.SendAsync(host, timeout, host)
Catch
End Try
End Sub))
Next
End Sub
Private Sub PingCompleted(ByVal sender As Object, ByVal e As PingCompletedEventArgs)
Dim ip As String = CStr(e.UserState)
If e.Reply IsNot Nothing AndAlso e.Reply.Status = IPStatus.Success Then
Dim hostname As String = GetHostName(ip)
Dim macaddres As String = GetMacAddress(ip)
Dim newIpAddress As IpInfo
newIpAddress.IpAddress = ip
newIpAddress.MacAddress = macaddres
newIpAddress.HostName = hostname
connectedIPAddresses.Add(newIpAddress)
Else
End If
End Sub
Public Function GetHostName(ByVal ipAddress As String) As String
Try
Dim entry As IPHostEntry = Dns.GetHostEntry(ipAddress)
If entry IsNot Nothing Then
Return entry.HostName
End If
Catch __unusedSocketException1__ As SocketException
End Try
Return Nothing
End Function
Public Function GetMacAddress(ByVal ipAddress As String) As String
Dim macAddress As String = String.Empty
Dim Process As System.Diagnostics.Process = New System.Diagnostics.Process()
Process.StartInfo.FileName = "arp"
Process.StartInfo.Arguments = "-a " & ipAddress
Process.StartInfo.UseShellExecute = False
Process.StartInfo.RedirectStandardOutput = True
Process.StartInfo.CreateNoWindow = True
Process.Start()
Dim strOutput As String = Process.StandardOutput.ReadToEnd()
Dim substrings As String() = strOutput.Split("-"c)
If substrings.Length >= 8 Then
macAddress = substrings(3).Substring(Math.Max(0, substrings(3).Length - 2)) & "-" & substrings(4) & "-" & substrings(5) & "-" & substrings(6) & "-" & substrings(7) & "-" + substrings(8).Substring(0, 2)
Return macAddress
Else
Return "OWN Machine"
End If
End Function
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Ping_all()
Threading.Thread.Sleep(10000)
For Each ip As IpInfo In connectedIPAddresses
ListBox1.Items.Add(ip.IpAddress)
Next
End Sub

Login form issue vb.net

I'm creating a student data management system and I'm stuck on the login form.
I've created a sign up form where the details entered are saved in a text file (Users.txt).
I can't seem to figure out what the problem is in the login form code (pasted below); it doesn't seem to recognise any saved login usernames and passwords.
Please help.
Thanks.
Imports System.IO
Public Class Registration
Dim myfilewriter As StreamWriter
Dim myfilereader As StreamReader
Dim strMyFilename As String
Dim intNumofRecs As Integer
Dim temp As String
Structure Users
Dim intUserID As Integer
Dim strusername As String
Dim strpassword As String
End Structure
Dim UsersArray() As Users
Private Sub readindata()
Dim intCounter As Integer
strMyFilename = "Users.txt"
myfilereader = New StreamReader(strMyFilename)
intNumofRecs = myfilereader.ReadLine
ReDim Preserve UsersArray(intNumofRecs)
intCounter = 0
Do Until myfilereader.EndOfStream = True
intCounter = intCounter + 1
UsersArray(intCounter).intUserID = myfilereader.ReadLine()
UsersArray(intCounter).strusername = myfilereader.ReadLine()
UsersArray(intCounter).strpassword = myfilereader.ReadLine()
Loop
myfilereader.Close()
End Sub
Private Sub btnNewUser_Click(sender As Object, e As EventArgs) Handles btnNewUser.Click
Me.Hide()
Sign_Up.Show()
End Sub
Private Sub Registration_Load(sender As Object, e As EventArgs) Handles MyBase.Load
readindata()
End Sub
Private Sub btnLogin_Click(sender As Object, e As EventArgs) Handles btnLogin.Click
Dim username As Boolean = False
Dim password As Boolean = False
Dim temp As String
myfilereader = System.IO.File.OpenText("Users.txt")
temp = myfilereader.ReadToEnd
myfilereader.Close()
If txtusername.Text = temp And txtpassword.Text = temp Then
username = True
password = True
Else
MsgBox("User not found")
End If
If username And password = True Then
txtusername.Text = ""
txtpassword.Text = ""
Me.Hide()
Dashboard.Show()
Else
End If
End Sub
End Class
and below is the code for the sign up form (how the text is saved to the users.txt file):
Public Sub SavetoTextFile()
Dim intCounter As Integer
readindata()
intNumofRecs = intNumofRecs + 1
ReDim Preserve UsersArray(intNumofRecs)
UsersArray(intNumofRecs).intUserID = intNumofRecs
UsersArray(intNumofRecs).strusername = txtUsername.Text
UsersArray(intNumofRecs).strpassword = txtPassword.Text
strMyFilename = "Users.txt"
myfilewriter = New StreamWriter(strMyFilename)
myfilewriter.WriteLine(intNumofRecs)
For intCounter = 1 To intNumofRecs
myfilewriter.WriteLine(UsersArray(intCounter).intUserID)
myfilewriter.WriteLine(UsersArray(intCounter).strusername)
myfilewriter.WriteLine(UsersArray(intCounter).strpassword)
Next
myfilewriter.Close()
End Sub
Private Sub btnSignUp_Click(sender As Object, e As EventArgs) Handles btnSignUp.Click
SavetoTextFile()
txtUsername.Text = ""
txtPassword.Text = ""
Me.Hide()
Registration.Show()
End Sub

Log in form and store username/passwords in a file in aray structure

Currently my code is:
Public Structure
Dim Username as String
Dim Password as String
Dim Read() As String = IO.File.ReadAllLines("Passwords.txt")
Dim PassArray(Read.Length - 1) As Account
For i = 0 To PassArray.Length - 1
Dim line() = Split(Read(i), ","c)
PassArray(i).Username = line(0)
PassArray(i).password = line(1)
Next
If PassArray(0).Username = txtUsername.Text Then
If PassArray(1).password = txtPassword.Text Then
Form1.Show()
End If
Else
MsgBox("Wrong Username or Password!")
End If
I get an 'index outside the bounds of the array at PassArray(i).password = line(1)
I think i may have structured this wrong
the test file looks like:
Username
Password
Try this, If you doesn't work, let me know and i will do my best to help you out :)
Imports System.IO
Public Class Form1
Public Structure info
Dim Username As String
Dim Password As String
End Structure
Dim details As info
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If TextBox1.Text = details.Username And TextBox2.Text = details.Password Then
MessageBox.Show("Correct!")
Form2.Show()
Me.hide()
Else
MessageBox.Show("wrong")
Textbox1.Clear()
Textbox2.Clear()
End If
End Sub
Public Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim FILE = System.IO.File.ReadAllLines("Passwords.txt")
Dim myArray As String() = FILE
details.Username = myArray(0)
details.Password = myArray(1)
End Sub
End Class
You don't have to use the Structure, but I included it because it was a part of your question. Happy Coding!

Making a string from a listbox

I have 2 projects, one which has a highscorelist stored on it, and one which tries to add highscores to that list and retrieve all items on the list. Trying to put items on the list works good, but retrieving the list doesn't work well. Here's the code:
Option Strict On
Option Explicit On
Imports System.Net.Sockets
Imports System.Threading
Public Class Main
Dim server As New TcpListener(45888)
Dim client As New TcpClient
Dim stream As NetworkStream
Dim connected As Boolean
Private Sub cmd_start_Click(sender As Object, e As EventArgs) Handles cmd_start.Click
server.Start()
cmd_start.Enabled = False
cmd_stop.Enabled = True
lbl_status.Text = "Running"
lbl_status.ForeColor = Color.Green
tmr.Start()
End Sub
Private Sub cmd_stop_Click(sender As Object, e As EventArgs) Handles cmd_stop.Click
server.Stop()
cmd_start.Enabled = True
cmd_stop.Enabled = False
lbl_status.Text = "Not running"
lbl_status.ForeColor = Color.Red
tmr.Stop()
End Sub
Private Sub Main_Load(sender As Object, e As EventArgs) Handles MyBase.Load
connected = False
CheckForIllegalCrossThreadCalls = False
End Sub
Dim x As Integer = 0
Private Sub tmr_Tick(sender As Object, e As EventArgs) Handles tmr.Tick
If server.Pending Then
client = server.AcceptTcpClient()
stream = client.GetStream()
tmr.Stop()
read()
Else
tmr.Start()
End If
lbl_mseconds.Text = "Relative time: " & x
x += 1
End Sub
Private Sub SendMessage(message As String)
Dim sendtext() As Byte = System.Text.Encoding.ASCII.GetBytes(message)
stream.Write(sendtext, 0, sendtext.Length)
stream.Flush()
End Sub
Private Sub read()
Dim rec(client.ReceiveBufferSize) As Byte
stream.Read(rec, 0, client.ReceiveBufferSize)
Dim rectext As String = System.Text.Encoding.ASCII.GetString(rec)
If rectext.Contains("#1#") Then
rectext = rectext.Substring(3)
If rectext.Split(CChar("-"))(0).Length = 2 Then rectext = "0" & rectext
If rectext.Split(CChar("-"))(0).Length = 1 Then rectext = "00" & rectext
listbox_highscores.Items.Add(rectext)
ElseIf rectext.Contains("#2#") Then
Dim tosend As String = listbox_highscores.Items(0).ToString
For i = 1 To listbox_highscores.Items.Count - 1
tosend &= "," & listbox_highscores.Items(i).ToString
Next
MsgBox(tosend)
SendMessage(tosend)
End If
tmr.Start()
End Sub
End Class
On the other project I have this:
Dim server As New TcpListener(45888)
Dim client As New TcpClient
Dim stream As NetworkStream
Friend Sub sendHighscore(name As String, score As Integer)
Try
client.Connect("192.168.1.127", 45888)
Catch ex As Exception
Exit Sub
End Try
stream = client.GetStream()
Dim sendtext() As Byte = Encoding.ASCII.GetBytes("#1#" & score & "-" & name)
stream.Write(sendtext, 0, sendtext.Length)
client = New TcpClient
End Sub
Friend Sub getHighscoreList()
ListBox_highscores.Items.Clear()
Try
client.Connect("192.168.1.127", 45888)
Catch ex As Exception
ListBox_highscores.Items.Add("Couldn't connect")
Exit Sub
End Try
stream = client.GetStream()
Dim sendtext() As Byte = Encoding.ASCII.GetBytes("#2#")
stream.Write(sendtext, 0, sendtext.Length)
client = New TcpClient
read()
End Sub
Private Sub read()
Dim rec(client.ReceiveBufferSize) As Byte
stream.Read(rec, 0, client.ReceiveBufferSize)
Dim rectext As String = Encoding.ASCII.GetString(rec)
Label2.Text = rectext
For Each item In rectext.Split(",")
ListBox_highscores.Items.Add(item)
Next
End Sub
Then when I use the sub sendHighscore() with a name and score, everything perfectly works and it shows in the other project on the list, but when I use the sub getHighscoreList() the list on the second project only contains the first item from the first list. Does someone has ideas?
Edit: Original answer removed entirely because it wasn't actually the problem (although it did offer improvements). My answer was nearly identical to this one anyway.
After analyzing this project much more closely, the problem with the For..Next loop not returning the expected results is because the strings are being sent back and forth as byte arrays in buffers much larger than necessary (client.ReceiveBufferSize). The actual "strings" received contain large amounts of non-printable characters (garbage) added to the end to fill the buffer. The quick and dirty solution is to remove all non-printable characters:
rectext = System.Text.RegularExpressions.Regex.Replace(rectext, _
"[^\u0020-\u007F]", String.Empty)
The whole Sub would read like this:
Private Sub read()
Dim rec(client.ReceiveBufferSize) As Byte
stream.Read(rec, 0, client.ReceiveBufferSize)
Dim rectext As String = System.Text.Encoding.ASCII.GetString(rec)
If rectext.Contains("#1#") Then
rectext = rectext.Substring(3)
If rectext.Split(CChar("-"))(0).Length = 2 Then rectext = "0" & rectext
If rectext.Split(CChar("-"))(0).Length = 1 Then rectext = "00" & rectext
rectext = System.Text.RegularExpressions.Regex.Replace(rectext, "[^\u0020-\u007F]", String.Empty)
listbox_highscores.Items.Add(rectext)
ElseIf rectext.Contains("#2#") Then
Dim tosend As String = listbox_highscores.Items(0).ToString
For i As Integer = 1 To (listbox_highscores.Items.Count - 1)
tosend &= "," & listbox_highscores.Items(i).ToString
Next
SendMessage(tosend)
End If
tmr.Start()
End Sub
Try this, your comma's are off as well...
Dim tosend As String = String.Empty
Dim intCount As Integer = 0
For i As Integer = 0 To listbox.Items.Count - 1
If intCount >= 1 Then
tosend &= "," & listbox.Items(i).ToString
Else
tosend &= listbox.Items(i).ToString
intCount += 1
End If
Next
MessageBox.Show(tosend)
Screenshot THAT IT WORKS!