Archive for the VB.net category.

Plocka ut filer ur katalog – VB.net

Plocka ut filer ur katalog – VB.net

Dim folderInfo As New IO.DirectoryInfo("c:\windows")
Dim arrFilesInFolder() As IO.FileInfo
Dim fileInFolder As IO.FileInfo

arrFilesInFolder = folderInfo.GetFiles("*.*")
For Each fileInFolder In arrFilesInFolder
ListBox1.Items.Add(fileInFolder.Name)
Next

Filed under: VB.net | Comments (0)

Få HTML från Webbrowser-komponenten

Få HTML från Webbrowser-komponenten

MsgBox(WebBrowser1.Document.Body.InnerHtml())

Filed under: VB.net | Comments (0)

VB.net: Webbrowser-component – Change Combobox

VB.net: Webbrowser-component – Change Combobox

Value ska stå kvar…

WebBrowser1.Document.GetElementById("id_record_type").SetAttribute("value", "CANADA")

Filed under: VB.net | Comments (0)

Loopa igenom och fyll form-element i VB.net

Loopa igenom form-element i VB.net

Dim elements = WebBrowser1.Document.Forms(0).Document.GetElementsByTagName("input")

For Each element In elements

MsgBox(element.name)
If element.name = "email" Then element.SetAttribute("value", "mail@hotmail.com")

Next

Filed under: VB.net | Comments (0)

VB.net MD5 – Create MD5 and Verify MD5

VB.net MD5 – Create MD5 and Verify MD5

Imports System
Imports System.Security.Cryptography
Imports System.Text

Module Example

' Hash an input string and return the hash as
' a 32 character hexadecimal string.
Function getMd5Hash(ByVal input As String) As String
' Create a new instance of the MD5 object.
Dim md5Hasher As MD5 = MD5.Create()

' Convert the input string to a byte array and compute the hash.
Dim data As Byte() = md5Hasher.ComputeHash(Encoding.Default.GetBytes(input))

' Create a new Stringbuilder to collect the bytes
' and create a string.
Dim sBuilder As New StringBuilder()

' Loop through each byte of the hashed data
' and format each one as a hexadecimal string.
Dim i As Integer
For i = 0 To data.Length - 1
sBuilder.Append(data(i).ToString("x2"))
Next i

' Return the hexadecimal string.
Return sBuilder.ToString()

End Function

' Verify a hash against a string.
Function verifyMd5Hash(ByVal input As String, ByVal hash As String) As Boolean
' Hash the input.
Dim hashOfInput As String = getMd5Hash(input)

' Create a StringComparer an compare the hashes.
Dim comparer As StringComparer = StringComparer.OrdinalIgnoreCase

If 0 = comparer.Compare(hashOfInput, hash) Then
Return True
Else
Return False
End If

End Function

Filed under: VB.net | Comments (0)

Remove item from array in VB.net

Remove item from array in VB.net:
Ta bort sak från array i vb.net

'1. order is not preserved In this approach, but very simple
MyArray(ItemToBeDeleted) = MyArray( Ubound (MyArray))
Redim Preserve MyArray( Ubound (MyArray) - 1)

'2. order Is maintained
Dim i As Long , N As Long
'assumes N is the position In MyArray to remove
For i = N To Ubound (MyArray) - 1
MyArray(i) = MyArray(i + 1)
Next i
Redim Preserve MyArray( Ubound (MyArray) - 1)

Filed under: VB.net | Comments (0)

VB.net – Check What Year

Kolla vilket år det är. Check what year it is.

If DateTime.Now.Year.ToString() = "2011" Then
MsgBox("The BETA isn't active anymore")
End
End If

Filed under: VB.net | Comments (0)

Läser in hela filen i en variabel – VB.net

Läser in hela filen i en variabel – VB.net

Public Function GetFileContents(ByVal FullPath As String, _
Optional ByRef ErrInfo As String = “”) As String

Dim strContents As String
Dim objReader As StreamReader
Try

objReader = New StreamReader(FullPath)
strContents = objReader.ReadToEnd()
objReader.Close()
Return strContents
Catch Ex As Exception
ErrInfo = Ex.Message
End Try
End Function

Filed under: VB.net | Comments (0)

Spara enkelt ner i textfil – VB.net

Så här sparar man enkelt ner något i txt-filer i VB.net

 

 

Public Function SaveTextToFile(ByVal strData As String, _

ByVal FullPath As String, _

Optional ByVal ErrInfo As String = “”) As Boolean

Dim Contents As String

Dim bAns As Boolean = False

Dim objReader As StreamWriter

Try

objReader = New StreamWriter(FullPath)

objReader.Write(strData)

objReader.Close()

bAns = True

Catch Ex As Exception

ErrInfo = Ex.Message

End Try

Return bAns

End Function

Filed under: VB.net | Comments (0)

Lista kataloger i VB.net

Så här listar man kataloger i VB.net:

 

files = System.IO.Directory.GetDirectories(FolderBrowserDialog1.SelectedPath)

For Each fname As String In files

MsgBox(fname)

Next

Filed under: VB.net | Comments (0)
-