Developers Archive for the 'Visual Basic' Category

Input Box function

Input Box function Monday, March 5th, 2007

Input box function is used to retrieve a input from the user

Parameters
The input box function takes three parameters:

InputBox PromptText, DialogTitle, DefaultText

The PromptText is a string containing the text to be displayed as the prompt. The DialogTitle is a string containing the text to be displayed in the dialog’s title, and DefaultText is a string containing the text to be already displayed in the text box.

Description

The code below displays the dialog box

InputBox “Please enter the name”,”Enter Name”, “Michael”

However, we need to know what the user entered! The InputBox function returns a string, which is the text the user entered in the Input Box.

Dim Name As String
Name = InputBox (”Please enter the name”, _
                  “Enter Name”, “Michael”)
Msgbox “The name is ” & Name

This displays an input box asking the user for a name. When the user clicks OK then a Message Box will be displayed showing the text the user entered. You will notice that if you press cancel, the message box is still displayed. When the cancel button is pressed, the InputBox returns an empty string. You can edit the code so the message box is not displayed if the user presses cancel, or does not type anything:

Dim Name As String
Name = InputBox (”Please enter the name”, _
                  “Enter Name”, “Michael”)
‘ If Name is not empty, display the message box
If Not Name = “” Then Msgbox “The name is ” & Name

How to Retrieve Parent Directory for Files and Folders

How to Retrieve Parent Directory for Files and Folders Thursday, March 1st, 2007

The following code will return the parent directory of a given directory , or the directory of a given filename.

Dim str as String
Dim i as Integer
str = “C:\Files\test\baby.jpg”
i = InStrRev(str, “\”)
str = Left(str, i)
MsgBox str

The output for the above code will be “C:\Files\test\”

If the input is a directory (F:\Program Files\MSN) it will return that directory’s parent (F:\Program Files\).
If the input is a file (F:\changes\MAR1\test.txt) it will return that file’s directory (F:\changes\MAR1\).

Convert ASCII to Binary string

Convert ASCII to Binary string Wednesday, February 28th, 2007

The  following code shows how to convert an ASCII integer to its binary string.

Public Function cBINARY(ByVal i As Integer) As String
Dim X As Long, Y As Long, bC As Byte
cBINARY = “”
X = 256
For Y = 1 To 8
     bC = 0
     X = X / 2
     If i >= X Then
     bC = 1
     i = i - X
     End If
   cBINARY = cBINARY & bC
Next Y
End Function
 
The above function returns the binary string which can be called and assigned to a string like this
strBinValue = cBINARY(AnyInteger)


All material @ copyrighted by chrisranjana.com. If you want to link to this article you are welcome to do so. Unauthorized publication is strictly prohibited. This developer tutorial website contains articles by Php programmers , Software developers, Mysql programmers and asp c# programmers. This website also contains ajax tutorials and advanced mysql sql stored procedures and functions tutorials and sample codes.