Random with min and max

Posted on August 9th, 2008 in VB. NET Functions by Terp

Simple as this:


Private Function RandomNumberAsString(ByVal Min As Int32, ByVal Max As Int32) As String
Return (New Random).Next(Min, Max).ToString
End Function

Example:
msgbox(RandomNumberAsString(2, 99))

Will open a dialog with a number between 2 and 99

Get Files In Dir

Posted on August 9th, 2008 in VB. NET Functions by Terp

Get the files in a dir:


Dim files() As String = System.IO.Directory.GetFiles("c:/")
For Each file In files
msgbox(file)
Next

Get Screen Resolution

Posted on August 9th, 2008 in VB. NET Functions by Terp

Get width and height of the screen:


Dim intX As Integer = Screen.PrimaryScreen.Bounds.Width
Dim intY As Integer = Screen.PrimaryScreen.Bounds.Height

Delay (sleep, wait, pause)

Posted on August 9th, 2008 in VB. NET Functions by Terp

This code allows you to pause your script, and allows it to do other stuff either than stop the entire app like sleep does:

Sub Delay(ByVal dblSecs As Double)

Const OneSec As Double = 1.0# / (1440.0# * 60.0#)
Dim dblWaitTil As Date
Now.AddSeconds(OneSec)
dblWaitTil = Now.AddSeconds(OneSec).AddSeconds(dblSecs)
Do Until Now > dblWaitTil
Application.DoEvents()
Loop

End Sub

Check Internet Connection

Posted on August 9th, 2008 in VB. NET Functions by Terp

I have seached the net for a simple solution and found this:

Private Function InternetGetConnectedState() As String
If My.Computer.Network.IsAvailable Then
If My.Computer.Network.Ping("google.dk", 1000) Then
Return True
Else
Return False
End If
Else
Return False
End If
End Function

example:
if InternetGetConnectedState = True then
msgbox(”ONLINE”)
else
msgbox(”OFFLINE)
end if