PDA

View Full Version : What are the correct VB naming conventions?


singularity2006
11-14-2003, 09:27 PM
http://www.emu.edu.tr/english/facilitiesservices/computercenter/bookslib/Web%20Database%20Developer's%20Guide%20with%20Visual%20Basic%205/htm/apb.htm <--- I found that...

but I can't find one for the little radio button select. U have ur standard check box, but what do you call the circular one and what is the correct prefix for it?

OC-NightHawk
11-14-2003, 09:30 PM
Visual Basic calls them option boxes so it stands to reason that the naming convention would be opt. Thats what I use.

singularity2006
11-15-2003, 12:40 AM
very cool, thanks. Now here's another question. The text we use shows us a little bit about how the option box is used. However, it only shows how it can do stuff as soon as you click it. However, here's what I want to do (but I don't know how to approach it):

User inputs some data into several text boxes. (first name, last name, ID#, date)
User selects type of equipment to checkout via selecting one of several option boxes (camera 1, camera 2, camcorder)

Then by clicking the command button "checkout," all inputs are saved to a CSV file and the most recent activity (the one just inputted), is displayed in a picture box. I know how to get the stuff inputted into the text box out to the picture box just fine. But how do I get the selection of the option box outputted to the picture box?

So option box 1: camera 1
Option box 2: camera 2
option box 3: camera 3

So if a user selects option box 2, how do I set an output to the picture box? The only thing I can think of @ the moment is to do a boolean test on each box in the sub that does the outputting. Does that sound about right?

And actually, on another note, I'm not totally sure about how to get the output to go to a CSV file (a test file would work fine too). What is the proper command line to export the data like that and continue appending to the txt file? I plan to use the above steps multiple times and have them all recorded to a log of some sort.

OC-NightHawk
11-15-2003, 01:09 AM
Originally posted by singularity2006
very cool, thanks. Now here's another question. The text we use shows us a little bit about how the option box is used. However, it only shows how it can do stuff as soon as you click it. However, here's what I want to do (but I don't know how to approach it):

User inputs some data into several text boxes. (first name, last name, ID#, date)
User selects type of equipment to checkout via selecting one of several option boxes (camera 1, camera 2, camcorder)

Then by clicking the command button "checkout," all inputs are saved to a CSV file and the most recent activity (the one just inputted), is displayed in a picture box. I know how to get the stuff inputted into the text box out to the picture box just fine. But how do I get the selection of the option box outputted to the picture box?

So option box 1: camera 1
Option box 2: camera 2
option box 3: camera 3

So if a user selects option box 2, how do I set an output to the picture box? The only thing I can think of @ the moment is to do a boolean test on each box in the sub that does the outputting. Does that sound about right?

And actually, on another note, I'm not totally sure about how to get the output to go to a CSV file (a test file would work fine too). What is the proper command line to export the data like that and continue appending to the txt file? I plan to use the above steps multiple times and have them all recorded to a log of some sort.

So you want the picture box to reflect which option box is selected?

You want to put all the code in the ok button. It could either be done with a numeric flag that has its value set based on the number or a nested if then statement. I personaly prefer the numeric flag option because it allows for the use of a Select Case block.

In the declerations section declare lngOnCamera as long. In form load set lngOnCamera equal to 0 or whatever default camera you wnat. Then in the ok button have this.

Private Sub cmdOK_Click()

If optCamera1.Value = True then
lngOnCamera = 1
End If

If optCamera2.Value = True then
lngOnCamera = 2
End If

If optCamera3.Value = True then
lngOnCamera = 3
End If

'*The above code is not needed if you add code within the option box to set lngOnCamera to its respective number when clicked.

Select Case lngOnCamera

case 1
Picture.Picture = LoadPicture(App.Path & "\Camera1.bmp")

case 2
Picture.Picture = LoadPicture(App.Path & "\Camera2.bmp")

case 3
Picture.Picture = LoadPicture(App.Path & "\Camera3.bmp")

End Select

End Sub

edit: a old simple way to write to a text file is this

'set the setting file name
SettingFileName = App.Path & "\config.umc"

'save the config to the config file so it doesn't always need to be done
Open SettingFileName For Output As #1
Write #1, ScreenWidth, ScreenHeight, ScreenDepth
Write #1, FarClipValue
Write #1, UseAA, SampleRate
Write #1, UseFog, FogUsed
Write #1, UseSpecular
Write #1, BGMusicVolumeLevel
Write #1, (Contrast / 1.5)
Close #1

If Err.Number <> 0 Then
MsgBox Err.Description & ", " & Err.Number
Exit Sub
End If

There is also the object orientated fso but its more complicated.

Option Explicit

Private fso As FileSystemObject
Private DebugFile As TextStream

Public DebugFileName As String

'_________________________________
'code inside a function or sub

If fso Is Nothing Then
Set fso = New FileSystemObject

Set DebugFile = fso.OpenTextFile(DebugFileName, ForWriting, True, TristateUseDefault)

DebugFile.WriteLine "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
DebugFile.WriteLine "Debugging Started: " & FormatDateTime(Now, vbGeneralDate)
DebugFile.WriteLine "Application: " & App.Title
DebugFile.WriteLine "Program file: " & App.EXEName
DebugFile.WriteLine "Version: " & FormatNumber(App.Major, 0) & "." & FormatNumber(App.Minor, 0) & _
"." & FormatNumber(App.Revision, 0)
DebugFile.WriteLine "Path: " & App.Path
DebugFile.WriteLine "Parameters: " & Command$
End If

If you use the FSO you need to ad a refrence to the Microsoft Scripting Runtime object. You know how to add project refrences?

singularity2006
11-15-2003, 01:37 AM
holy geez wow, thanks for the information (that's a lot of information). Hah the very last question of yours, I'm not too sure. This is an intro to Visual Basic course, and I have no other background in programming except HTML 3.0 and modifications of well documented JavaScript.... so that means we haven't gotten far enough to know how to reference project preferences (or maybe we have and it's under a different term?). But as for the stuff above that, it makes a kind of sense. I'll write the cases down into the program and see where things go from there. Btw, what is the purpose of setting OnCamera as long if it's a boolean test, just 1 or 0 or true/false (or am I missing something?)? And what does the prefix of lngOn mean for the object "camera?" I'm assuming lng is long but what is On?

OC-NightHawk
11-15-2003, 02:09 AM
Ok adding a refrence to a vb project is really simple no code involved like c++ and its header files. Of course I'm guessing deep under VB's sfety net its doing it for you based on the gui menu.

Anyways click on project->refrences. Then in this case check the Microsoft Scripting runtime and click ok. You can now make use of the file system object.

Originally posted by singularity2006
Btw, what is the purpose of setting OnCamera as long if it's a boolean test, just 1 or 0 or true/false (or am I missing something?)? And what does the prefix of lngOn mean for the object "camera?" I'm assuming lng is long but what is On?

The prefix lng is short for long with is the variable type. The reason you'd want to use the long instead of a boolean is because you'd need three booleans and a complicated if statement to do the same thing. Where the long's value can reflect 1, 2, or 3 being true and not giving a hoot which where false, a boolean could only tell you if one of the camera's was true or false. lngOnCamera is long On Camera, for example the picture is on camera 1.

singularity2006
11-15-2003, 02:30 AM
Cool cool. So would Dim As Single work as well?

Btw, just a testament to laziness question, I noticed MS Visual Basic Suite won't let me use my scrolling wheel on my MS Intellimouse Explorer. Is there a way to enable this so I can more quickly scroll through my code?

OC-NightHawk
11-15-2003, 02:43 AM
Originally posted by singularity2006
Cool cool. So would Dim As Single work as well?

Btw, just a testament to laziness question, I noticed MS Visual Basic Suite won't let me use my scrolling wheel on my MS Intellimouse Explorer. Is there a way to enable this so I can more quickly scroll through my code?

You want to declare the OnCamera as a single? I wouldn't. It takes up a lot mre memory and is slower. The point of a single is to be able to have more accurate decimal precision. If you want to use a smaller weight variable type I'd use byte. Byte would have the least memory footprint and get the job done.

CGTalk Moderation
01-16-2006, 05:00 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.