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.
Related
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
I'm trying to make a login window and a main window. The problem is when I close the login form and show the main window, the whole program stops.
The login form:
Imports System.IO
Imports System.Text
Imports System.Net
Public Class frmLogin
Dim address As String = "http://puu.sh/jKJ**Zq/d613de****29.txt"
Dim client As WebClient = New WebClient()
Private Sub frmLogin_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'frmMain.Close()
End Sub
Private Sub frmLogin_Close(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Me.FormClosed
frmMain.Show()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If attemptLogin() Then
MsgBox("Login Successful")
Me.Close()
'frmMain.Show()
Else
MsgBox("Username or password is incorrect")
End If
End Sub
Private Function attemptLogin()
Dim reader As StreamReader = New StreamReader(client.OpenRead(address))
Dim line As String
Dim username As String
Dim password As String
line = reader.ReadLine()
Do While Not line Is Nothing
username = line.Split(":")(0)
password = line.Split(":")(1)
If (username = TextBox1.Text And password = TextBox2.Text) Then
Return True
End If
line = reader.ReadLine()
Loop
reader.Close()
client.Dispose()
Return False
End Function
Private Function Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim client As WebClient = New WebClient()
Dim reader As StreamReader = New StreamReader(client.OpenRead(address))
Dim line As String
line = reader.ReadLine
Do While Not line Is Nothing
line = reader.ReadLine()
Loop
reader.Close()
Dim writer As StreamWriter = New StreamWriter(client.OpenRead(address))
writer.Write(TextBox1.Text & ":" & TextBox2.Text)
writer.Close()
client.Dispose()
Return False
End Function
End Class
The Main Window:
Public Class frmMain
Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Me.Load
'frmMain.Close()
End Sub
Private Sub frmMain_closed(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Me.FormClosing
End Sub
End Class
I am fairly new to VB.NET so sorry about the lack of knowledge/ugly coding. I'm used to programming GUIs in Java.
You need to set your 'Shutdown mode' to 'When last form closes'.
You can find this setting by going to My project and then clicking on Application (the first tab).
You can then find the setting at the bottom.
im making a program for school (in VB.NET) where i have a listview. When the user enters a customer name and presses "OK"it is outputted in the listview as a "o"
the code for the program is:
Public Class Form1
Dim w As IO.StreamWriter
Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
lstOutput.Items.Clear()
End Sub
Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
End
End Sub
Private Sub PrintToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PrintToolStripMenuItem.Click
Dim sfile As New SaveFileDialog
With sfile
.Title = "Choose your path to save the information"
.InitialDirectory = "C:\"
.Filter = ("ONLY Text Files (*.txt) | *.txt")
End With
If sfile.ShowDialog() = Windows.Forms.DialogResult.OK Then
Dim Write As New IO.StreamWriter(sfile.FileName)
Dim k As ListView.ColumnHeaderCollection = lstOutput.Columns
For Each x As ListViewItem In lstOutput.Items
Dim StrLn As String = ""
For i = 0 To x.SubItems.Count - 1
StrLn += k(i).Text + " :" + x.SubItems(i).Text + Space(3)
Next
Write.WriteLine(StrLn)
Next
Write.Close() 'Or Write.Flush()
End If
End Sub
Private Sub txtDiscPrice_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
Private Sub btnAdd_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
Dim secondform As New Form2
secondform.ShowDialog()
Dim item As ListViewItem
item = lstOutput.Items.Add(secondform.CustomerName)
item.SubItems.Add(secondform.Item)
item.SubItems.Add(secondform.ItemPrice)
item.SubItems.Add(secondform.Quantity)
item.SubItems.Add(secondform.TotalPrice)
item.SubItems.Add(secondform.DiscPerc)
item.SubItems.Add(secondform.DiscPrice)
item.SubItems.Add(secondform.PaymentMethod)
End Sub
End Class
and for the second form, where the user enters the information the code is:
Public Class Form2
Public CustomerName As String
Public Item As String
Public ItemPrice As Double
Public Quantity As Integer
Public TotalPrice As Integer
Public DiscPerc As Double
Public DiscPrice As Double
Public PaymentMethod As String
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
CustomerName = Val(txtCustName.Text)
Item = Val(txtItemName.Text)
ItemPrice = Val(txtItemPrice.Text)
Quantity = Val(txtQuantity.Text)
TotalPrice = Val(txtTtlPrice.Text)
DiscPerc = Val(txtDiscPerc.Text)
DiscPrice = Val(txtDiscPrice.Text)
PaymentMethod = Val(txtPaymentMethod.Text)
Me.Close()
End Sub
End Class
I've been stuck on this for ages, any help is appreciated!
I was trying to display data from file in a list saved on the hard drive by clicking on a button, however I'm not sure on haw to do it properly:
Private Sub btnListRecipes_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnListRecipes.Click
Dim TextLine As String
If System.IO.File.Exists(Filename) = True Then
Dim RecipeReader As New System.IO.StreamReader(Filename)
Do While RecipeReader.Peek() <> -1
TextLine = TextLine & RecipeReader.ReadLine() & vbNewLine
Loop
lstRecipes.Text = TextLine.Text
Else
MsgBox("File Does Not Exist")
End If
End Sub
I would be really grateful for assistance :D
Private Sub btnListRecipes_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnListRecipes.Click
Try
lstRecipes.AddRange(File.ReadAllLines(FileName))
Catch
MsgBox("Unable to read file")
End Try
End Sub
Use:
lstRecipes.Items.Add(TextLine.Text)
More specifically before it jumps to the next item in the list, so this would go right after your assignment of TextLine.
you can do this:
Imports System
Imports System.IO
Public Class Form1
Public Shared listTXT, listOfTxt, listOfTxtFile As New List(Of String)
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim path As String = "C:\myDirectory\"
Dim parentinfo As New DirectoryInfo(path)
' Store Text file name in a list
For Each txtFile As FileSystemInfo In parentinfo.GetFileSystemInfos()
listTXT.Add(txtFile.Name)
Next
' Store Path of Text file in a list
For noOfTxtFile = 0 To listTXT.Count - 1
Dim pathOfFile As String = path & listTXT(noOfTxtFile)
listOfTxtFile.Add(pathOfFile)
Dim obj As System.IO.StreamReader
obj = System.IO.File.OpenText(pathOfFile)
While Not obj.EndOfStream
listOfTxt.Add(obj.ReadLine)
End While
Next
Dim lineOfTxt As Integer
Dim txt As String
For lineOfTxt = 0 To listOfTxt.Count - 1
txt = listOfTxt(lineOfTxt)
ListBox1.Items.Add(txt)
Next
End Sub
End Class
how to store string value in date variable in vb.net
i am using the following code
dim dtBL as Date
txtBLDate.text="23/11/2010"
dtBL = Format(CDate(txtBLDate.Text), "MM/dd/yyyy")
but i am getting the error which says that 'Conversion from string "23/11/2010" to type 'Date' is not valid.'
please advice on this
Two rules of thumb I give everyone with VB.Net:
Turn Option Strict On
Abandon the Microsoft.VisualBasic-Namespace ASAP
To answer your question, your date is in the format dd/MM/yyyy and not MM/dd/yyyy.
i am using vb.net in web applications
i put a page code that may be helping you dealing with dates
ASPX
code behind
Partial Class DateFormatConversions Inherits System.Web.UI.Page Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
lblDate.Text = Today.ToString("M/d/yyyy")
End Sub
Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
lblDate.Text = Today.ToString("MM/dd/yyyy")
End Sub
Protected Sub Button3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button3.Click
lblDate.Text = Today.ToString("d/M/yyyy")
End Sub
Protected Sub Button4_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button4.Click
lblDate.Text = Today.ToString("dd/MM/yyyy")
End Sub
Protected Sub Button5_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button5.Click
Dim DTFI As New System.Globalization.DateTimeFormatInfo
DTFI.ShortDatePattern = DropDownList1.SelectedValue
Dim addedDate As DateTime
addedDate = DateTime.Parse(TextBox1.Text, DTFI)
lblDateOutput.Text = addedDate.ToLongDateString
End Sub End Class
Imports Microsoft.VisualBasic Imports System.Globalization Public Class DatumKonvert1 Public Shared Function DK1(ByVal myDMstring As String) As Date
Dim source As String = myDMstring
Dim d As DateTime = DateTime.ParseExact(source, "d'/'M'/'yyyy", CultureInfo.InvariantCulture)
Dim resultMydate As String = d.ToString("M'/'d'/'yyyy")
Dim mdx = DateTime.ParseExact(resultMydate, "M'/'d'/'yyyy", CultureInfo.InvariantCulture)
Return mdx End Function End Class