How do get only available ssid with visual basic 2010 - vb.net

Sorry for bad english
I want the available ssid list in listbox
I am use api and its work but It stopped working after a while.And not see current wifi list.
My code:
Imports deneme2.NativeWifi
Imports System.Text
Public Class Form1
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Timer1.Start()
End Sub
Private Sub scan()
On Error Resume Next
Dim client As New WlanClient
ListView1.Items.Clear()
For Each wlanIface As WlanClient.WlanInterface In client.Interfaces
Dim networks() As Wlan.WlanAvailableNetwork = wlanIface.GetAvailableNetworkList(0)
For Each network As Wlan.WlanAvailableNetwork In networks
Dim ssid As Wlan.Dot11Ssid = network.dot11Ssid
Dim networkName As String = Encoding.ASCII.GetString(ssid.SSID, 0, CType(ssid.SSIDLength, Integer))
Dim item As ListViewItem = New ListViewItem(networkName)
item.SubItems.Add(network.dot11DefaultCipherAlgorithm.ToString())
item.SubItems.Add(network.wlanSignalQuality.ToString + "%")
ListView1.Items.Add(item)
Next
Next
End Sub
Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
scan()
End Sub
End Class

Related

vb.net System.ArgumentOutOfRangeException When Trying to ping

been trying to follow this guide on how to make picture boxes change colour depending on if the ping has been successful or not. I have some test ip's in a CSV file that the program imports
but I keep getting a exception error. I have 3 picture boxes on the page currently defined from picturebox2 - 4
the code for the whole page is below, any suggestions or fixes would be greatly appreciated
Imports System.Net
Imports System.Net.NetworkInformation
Imports System.Threading
Imports System.IO
Imports System.Timers
Public Class Central
Dim pingTable As DataTable = New DataTable()
Dim ipAddress As List(Of String) = New List(Of String)
Dim pictureBoxList As List(Of PictureBox) = New List(Of PictureBox)
Dim timer As Timers.Timer
Public Sub New()
' This call is required by the designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
timer = New Timers.Timer
timer.Interval = 20000
timer.Enabled = True
AddHandler timer.Elapsed, AddressOf OnElapsedTime
End Sub
Private Sub OnElapsedTime(ByVal sender As Object, ByVal e As ElapsedEventArgs)
BackgroundWorker1.RunWorkerAsync()
End Sub
Private Sub FillPingTable()
pingTable.Columns.Add("ip", GetType(String))
pingTable.Columns.Add("picturebox", GetType(String))
pingTable.Rows.Add()
For i As Integer = 0 To ipAddress.Count - 1
pingTable.Rows.Add(ipAddress(i), pictureBoxList(i))
Next
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Hide()
Scot.Show()
End Sub
Private Sub PictureBox1_Click(sender As Object, e As EventArgs) Handles PictureBox1.Click
Hide()
Home.Show()
End Sub
Private Sub central_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Using reader = New StreamReader("A:\IpAddress.csv")
While Not reader.EndOfStream
Dim line = reader.ReadLine
Dim values = line.Split(ChrW(10))
ipAddress.Add(values(0))
End While
For i As Integer = 1 To 2
pictureBoxList.Add(CType(Controls.Find("PictureBox" & i, True)(0), PictureBox))
FillPingTable()
BackgroundWorker1.RunWorkerAsync()
Next
End Using
End Sub
Private Sub BackgroundWorker1_DoWork(sender As Object, e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
Thread.Sleep(500)
Parallel.For(0, ipAddress.Count(), Sub(i, loopState)
Dim ping As New Ping()
Dim pingReply As PingReply = ping.Send(ipAddress(i).ToString())
Me.BeginInvoke(CType(Sub()
pictureBoxList(i).SizeMode = PictureBoxSizeMode.Zoom
pictureBoxList(i).BackColor = If(pingReply.Status = IPStatus.Success, Color.Green, Color.Red)
End Sub, Action))
End Sub)
End Sub
End Class

Save text on my.settings saved multiple times vb.net

i have start a new application to encrypt strings and save them on my settings the code its work fine but wen it save it save multiple times the same.
How can i do for save all the content from a listbox to my settings with out to repeat.
This is my code
Imports System.Text
Imports System.Security.Cryptography
Imports System
Imports System.Collections
Imports System.Collections.Specialized
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'My.Settings.md5_hashes.Clear()
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim md5 As MD5 = System.Security.Cryptography.MD5.Create()
Dim inputBytes As Byte() = System.Text.Encoding.ASCII.GetBytes(TextBox1.Text)
Dim hash As Byte() = md5.ComputeHash(inputBytes)
Dim sb As New StringBuilder()
For i As Integer = 0 To hash.Length - 1
sb.Append(hash(i).ToString("x2"))
Next
TextBox2.Text = sb.ToString
ListBox1.Items.Add(TextBox1.Text + "<--->" + TextBox2.Text)
My.Settings.md5_hashes.Add(TextBox1.Text + "<--->" + TextBox2.Text)
My.Settings.Save()
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
For Each item In My.Settings.md5_hashes
ListBox1.Items.Add(item)
Next
Timer1.Start()
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
For Each item In My.Settings.md5_hashes
ListBox1.Items.Add(item)
Next
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
TextBox1.Text = ""
TextBox2.Text = ""
End Sub
End Class
Well i just solved my self the problem its because wen i start the timer its is there the code to retrieved all the content from my settings to the listbox.
I just removed and solved.

Why is my form not loading data from .mdb file?

This is a homework assignment that I am working on. I have an .mdb file that is supposed to connect to my application and then I should be able to navigate among the records. The database is connected as a data source. But, when I run the application no data is populated and I get a IndexOutOfRangeException was unhandled error when I press a button on my toolstrip. I have tried to ask for assistance from the professor but she has been non-existent all semester. What am I doing wrong here? I'm only looking for help for where to focus my attention so that I can figure this out on my own.
Public Class Form1
Dim strMemoryConnection As String = "Provider = Microsoft.Jet.OLEDB.4.0; Data Source = " &
Application.StartupPath & "\memory.mdb"
Dim strSQLMem As String
Dim dtMem As New DataTable()
Dim intTotalRows As Integer
Dim intCurrentRow As Integer
Private Sub displayRecord()
Me.txtTitle.Text = CStr(dtMem.Rows(intCurrentRow)("title"))
Me.txtAuthor.Text = CStr(dtMem.Rows(intCurrentRow)("author"))
Me.txtPublisher.Text = CStr(dtMem.Rows(intCurrentRow)("publisher"))
Me.txtStuff.Text = CStr(dtMem.Rows(intCurrentRow)("stuff"))
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventHandler)
dtMem.Clear()
strSQLMem = "SELECT * FROM Memory"
Dim dataAdapter As New OleDb.OleDbDataAdapter(strSQLMem, strMemoryConnection)
dataAdapter.Fill(dtMem)
dataAdapter.Dispose()
intTotalRows = dtMem.Rows.Count
intCurrentRow = 0
displayRecord()
End Sub
#Region "Tool Strip Button Clicks"
Private Sub btnTop_Click(sender As Object, e As EventArgs) Handles btnTop.Click
intCurrentRow = 1
displayRecord()
End Sub
Private Sub btnPrev_Click(sender As Object, e As EventArgs) Handles btnPrev.Click
intCurrentRow = intCurrentRow - 1
If intCurrentRow < 0 Then
intCurrentRow = 1
End If
displayRecord()
End Sub
Private Sub btnNext_Click(sender As Object, e As EventArgs) Handles btnNext.Click
intCurrentRow = intTotalRows + 1
If intCurrentRow = intTotalRows Then
intCurrentRow = intTotalRows - 1
End If
displayRecord()
End Sub
Private Sub btnBot_Click(sender As Object, e As EventArgs) Handles btnBot.Click
intCurrentRow = intTotalRows - 1
displayRecord()
End Sub
#End Region
End Class
In the end, it was as I expected. The data was not loading properly. I finally realized that the Form1_Load argument was not correct.
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventHandler)
Needed to be:
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
I will be letting my professor and fellow classmates know that this is incorrect.
Thanks to Bugs for the troubleshooting. At the least, I now know how to create a SQL connection very easily. I also appreciate whomever downvoted my question and their help in figuring this out.

Error: Form1 is a type of windowsApplication cannot be used as an expression

How to solve error when passing and returning some data across the form in visual basic.
Error: Form1 is a type of windowsApplication cannot be used as an
expression
showin error on "Form 1" (Public Class Form1)
FORM 1 CODE
Public Class Form1
Dim eid As String = ""
Public Sub New(ByVal empid As String)
InitializeComponent()
eid = empid
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'Declare a variable of string type
Dim pass As String = TextBox1.Text
Dim frm As New Form2(pass)
frm.ShowDialog()
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Label2.Text = eid.ToString()
End Sub
End Class
FORM 2 CODE
Public Class Form2
Dim eid As String = ""
Public Sub New(ByVal empid As String)
InitializeComponent()
eid = empid
End Sub
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Label1.Text = eid.ToString()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim value As String = TextBox2.Text
Dim fr As New Form1(value)
fr.ShowDialog()
End Sub
End Class
To solve your error message add this to your Form1 Class
Public Sub New()
InitializeComponent()
End Sub
If you are trying to pass values between forms, you might find this link useful...
http://grantwinney.com/passing-data-between-two-forms-in-winforms/
Public Class Form1
Dim eid As String = ""
Public Sub New(ByVal empid As String)
InitializeComponent()
eid = empid
End Sub
Public Sub New()
InitializeComponent()
End Sub
startup form isn't being called with any parameters
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'Declare a variable of string type
Dim pass As String = TextBox1.Text
Dim frm As New Form2(pass)
frm.ShowDialog()
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Label2.Text = eid.ToString()
End Sub
End Class
It happens when you change the project type from class library to windows forms in visual studio.
Head to Application.Designer.vb in your project and there you'll find something like this:
Namespace My
'NOTE: This file is auto-generated; do not modify it directly. To make changes,
' or if you encounter build errors in this file, go to the Project Designer
' (go to Project Properties or double-click the My Project node in
' Solution Explorer), and make changes on the Application tab.
'
Partial Friend Class MyApplication
<Global.System.Diagnostics.DebuggerStepThroughAttribute()> _
Public Sub New()
MyBase.New(Global.Microsoft.VisualBasic.ApplicationServices.AuthenticationMode.Windows)
Me.IsSingleInstance = false
Me.EnableVisualStyles = true
Me.SaveMySettingsOnExit = true
Me.ShutDownStyle = Global.Microsoft.VisualBasic.ApplicationServices.ShutdownMode.AfterMainFormCloses
End Sub
<Global.System.Diagnostics.DebuggerStepThroughAttribute()> _
Protected Overrides Sub OnCreateMainForm()
Me.MainForm = Global.AeonLabs.Layouts.Main.mainAppLayoutForm
End Sub
End Class
End Namespace
in the sub OnCreateMainForm() where it has OnCreateMainForm change it to something like this
Protected Overrides Sub OnCreateMainForm()
Me.MainForm = New Global.AeonLabs.Layouts.Main.mainAppLayoutForm
End Sub
and you'll be good to go!!

Data substring not showing full value

My code should be showing 32 characters but it's only showing 7. This is the code I currently have:
Imports System.IO
Public Class Form1
Private Property sr As Object
Private Sub BrowseBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BrowseBtn.Click
OpenFileDialog.ShowDialog()
FilePathLabel.Text = OpenFileDialog.FileName
End Sub
Private Sub SearchBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SearchBtn.Click
Dim sr As StreamReader = New StreamReader(OpenFileDialog.FileName)
Dim data = sr.ReadToEnd()
Dim pos = data.IndexOfAny("LASTSAVE")
If pos >= 0 Then
End If
CatiaVersionLabel.Text = data.Substring(pos, 32)
End Sub
End Class
Not too sure why it's doing this as the text that needs to be found is there when I open it independently.