A reader sent these in noting that these questions were used in his company for interviewing prospective VB programmers.
- How do you center a form?
- Can I send keystrokes to a DOS application?
- Convert an RGB value to a long, or a long to RGB.
- Implement smooth scrolling for either text, graphics or controls across a form.
- Implement some quick and easy encryption (can be something primitive).
- 4 different types of sorts: advantages and disadvantages.
- Compute CRC32 checksum, write a quick piece of code that accepts the packet of data and returns the CRC.
- How do you use the Mouse OFF event?
- How do I call Windows Help files from a VB program?
- How do I create a textbox that lets you insert tabs?
- How do I make text box that displays asterisks when the user types in data such as password?
- How do I create multi-column combo box?
- How do I make a menu popup from a CommandButton?
- How to create menus at run time in VB?
- Write a generic error handling routine.
- How to copy text to the Windows clipboard and from it.
- How can I call a Command button without clicking it?
- Write a simple app with Encrypt and Decrypt buttons and Textbox where the user can enter text for encryption and decryption.
71 Comments on Basic VB interview questions
Answer for Qn. No. 41
Each & Every textbox in VB , has the Event “Keydown” and from there you can trap the Alt Key.
To Test this give a simple statement,
Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
MsgBox KeyCode
End Sub
If u press alt key on that text, u will get the result.
Ans for Q. 1 we can center a from by setting its startup position property to center
To make a menu popup from a CommandButton-
U can use following link which has illustrated it.also u can get the code for menu at runtime.
http://www.mvps.org/vbvision/_samples/TrackMouseEvent_Demo.zip
Ans for Q 13-
PopupMenu menuname
ex. popupmenu mnufile
Ans for Q.15-
Public sub command_click()
On error goto noerr
.
.
code
.
noerr:
msgbox Err.number & ” ” & err.description
End Sub
for the 17th Question There is no value property for the command button,
that is cancel property
17th Question : Command Buttons have Value property, When ever you execute the statement Cmd_Save.Value=true
1. Cmd_Save_Click() event called and the statements are executed wihin the event.
2. Usage of The Cancel property of a command button is : to execute code with in the command button when you press ‘Esc’ key:
eg: Cmd_Save.Cancel = True ‘When you press ‘Esc’ Key the Cmd_Save_Click event executed
3. Usage of The Default property of a command button is : to execute code with in the command button when you press ‘Enter’ or ‘Return’ Key:
eg: Cmd_Save.Default = True ‘When you press ‘Enter’ or ‘Return’ Key the Cmd_Save_Click event executed
Ans 36. To register a ActiveX dll : run the command in dos window or RUN window
regsvr [pathname\dllName.dll]
to unregister
regsvr/u [pathname\dllName.dll]
Ans for Q-18….
Private Sub CmdDecrypt_Click()
If Trim(TxtEncrypt.Text) = “” Then Exit Sub
LblEncrypt = “Decrypted Text : ”
TxtResult = M_Fn_EncryptDecrptPWD(Trim(TxtEncrypt.Text))
End Sub
Private Sub CmdEncrypt_Click()
If Trim(TxtEncrypt.Text) = “” Then Exit Sub
LblEncrypt = “Encrypted Text : ”
TxtResult = M_Fn_EncryptDecrptPWD(Trim(TxtEncrypt.Text))
End Sub
Public Function M_Fn_EncryptDecrptPWD(CurPassword As String) As String
Dim gfn_name As String
On Error GoTo ERRPART:
Dim intLength As Integer
Dim iIndexPos As Integer
Dim sSourceStr As String
Dim sDecrptStr As String
Dim sStrChar As String
Dim iAscValue As Integer
Dim iConvValue As Integer
gfn_name = “M_Fn_EncryptDecrptPWD”
sSourceStr = CurPassword
intLength = Len(sSourceStr)
If intLength = 0 Then
M_Fn_EncryptDecrptPWD = “”
Exit Function
End If
sDecrptStr = “”
For iIndexPos = 1 To intLength
sStrChar = Mid$(sSourceStr, iIndexPos, 1)
iAscValue = Asc(sStrChar)
iConvValue = iAscValue Xor 80
sDecrptStr = sDecrptStr + Chr(iConvValue)
Next iIndexPos
M_Fn_EncryptDecrptPWD = sDecrptStr
Exit Function
ERRPART:
MsgBox Err.Description & Space(2) & ” - ” & gfn_name, vbCritical, mg_sProductTitle
‘MsgBox Err.Description & Space(2) & gfn_name, vbCritical
M_Fn_EncryptDecrptPWD = “”
End Function
forms Option statement
OPtion Explicit - Variable Declaration
Option base - Array lower bound
Option compair -text comparing
For the life of me, I can’t understand why do tech companies have this kind of interview.
Should they focus more on problem solving skills than quiz applicants on things that they might not know off-hand but can be researched somewhere?
They might unintentionally pick a “bookish” applicant instead of an applicant that understands “real life” issues better.
In the long run, even an average programmer will eventually become proficient in coding for the intended software once he/she understands how the application works.
1. For displaying Help file here is the code:
Private Declare Function WinHelp Lib “user32″ Alias “WinHelpA” (ByVal hwnd As Long, ByVal lpHelpFile As String, ByVal wCommand As Long, ByVal dwData As Long) As Long
Private Const HELP_CONTENTS = 5
Private Const HELP_FINDER = 11
Private Sub Command1_Click()
Dim lResult As Long
Dim sHelpFile As String
Dim lCommand As Long, lOption As Long
sHelpFile = “windows.hlp”
lCommand = HELP_CONTENTS
lOption = 0
lResult = WinHelp(Me.hwnd, sHelpFile, lCommand, lOption)
End Sub
2.Difference betn Activex EXE (out process server) & Actives DLL (inprocess server):
->DLL runs in the same space(memory) as that of application where as exe runs as a seperate process.
->hence using dll is faster compared to using exe
what is the difference between dll and ocx control ?
How to create ini file in VB, please tell me the simple method.
How can i call a command button without clicking it?
Way To Get Connection String at your own:
Steps:
1) Create file in notepad as filename.txt leave it blank.
2) Save As it {path]/filename.udl and exit the Notepad.
3) Open the My Computer-> goto the ->file and just double Click.
4) it Automatically open with the wizard that make your Connection task easy.
5) open your file with Notepad.
6) and you get the Connection String of any kind of server of Windows.
Any Problem
contact : yogihanu@yahoo.com
Thanks
How to show a pregress bar on a VB form when a stored procedure is getting executed at the back-ground?
is there non event contrls?
How do you center a form?
Ans: its easy
First you findout width and height of the screen
the code for this is(use me or formname, me is nothing but active form)
me.left=screen.width/2-me.width/2
me.top=screen.height/2 -me.height/2
place these two line of the code in form load event.
Implement some quick and easy encryption (can be something primitive).
ans:
say you want to convert into encrypted format( not in orginal text, primitive)
code:
test=”Text to be converted”
encry=”"
for i=1 to len(test)
encry=encry+chr(ASC((mid(test,i,1))+38)
next i
msgbox (encry)
Hi One And All,
This is sample Code For Calling
CommandButton Click Event Without manually user click.
Ex:
Private Sub Command1_Click()
Msgbox “You Clicked Command button With _
Out Manually Click”
End Sub
Ex: Call Command Button From Load Event
Private Sub Form_Load
Call Command1_Click
End Sub
Thank YOu