# BASIC/Visual BASIC Thread



## Cromewell

Please post any questions relating to BASIC/Visual BASIC here. Please also specify which external libraries, if any, you are using.

You can also use this thread to post code you wish to share.


----------



## FXB

This is a project.

I have to create a menu from which a customer can order breakfast or lunch.
The customer should be able to enter his name

choose to order from the breakfast or lunch menu

for each menu the customer must be able to select the items which items  he wants.
the price for each item must be displayed beside the item.

Once the customer is done ordering he must confirm by pressing a confirmation button

then a new window opens displaying a summary of the order including the customers name the total and the possibility to add a tip.  The total price should change according to the tip.

How would I do this?

I use Visual Basic Express edition 2008


----------



## Cromewell

What exactly are you looking for? I won't do your homework but I don't mind helping you with certain aspects of it.

In this case, it's a relatively simple project so I'd suggest planning out/designing the initial UI that will be presented then slowly building up the backing code and any other UI objects you need to make it work.

I'm not big on VB2008, the last version I used was 6.


----------



## Dropkickmurphys

Cromewell said:


> What exactly are you looking for? I won't do your homework but I don't mind helping you with certain aspects of it.
> 
> In this case, it's a relatively simple project so I'd suggest planning out/designing the initial UI that will be presented then slowly building up the backing code and any other UI objects you need to make it work.
> 
> I'm not big on VB2008, the last version I used was 6.



There's quite a difference between VB.NET and VB6 I believe. VB.NET is object-oriented, where as VB6 is more procedural I believe?


----------



## FXB

Well my first concern is the UI I'm not sure what to make of it.

what would be best?

1. have a window asking for the customer's name and choice of menu.  From there open a new window displaying the desired menu Then just do a list and add the prices

or should I do it all in one window?  point my in the right direction


----------



## zombine210

Hi!
i'm trying to write a script to check free disk space on my file server. so far i have this



> On Error Resume Next
> strComputer = "."
> 
> Set objWMIService = GetObject("winmgmts:" _ &
> "(impersonationLevel=impersonate)!\\" & strComputer & "\root\cimv2")
> 
> Set colItems = objWMIService.ExecQuery("Select * from Win32_LogicalDisk Where DriveType = 3")
> 
> For Each objItem in colItems
> 
> Wscript.Echo objDisk.DeviceID &  "=" & Int(objDisk.Size /1048576) & "MB   " & FormatPercent(objDisk.FreeSpace / objDisk.Size) * 100) & "% Free"
> 
> Next



i know i'm trying to output too much info in one line, but i'm trying to keep it as simple as possible.

i'm getting this error"


> >cscript disk.vbs > disk.txt
> C:\...\disk.vbs(4, 45) Microsoft VBScript compilation error: Invalid char
> acter



i've already rewritten this a few time, still geting the same error


----------



## zombine210

ok i deleted the underscore from the third line. i don't get the error anymore.
but now i run the script and there is no output


----------



## zombine210

ok, i removed this bit altogether
_ &
"(impersonationLevel=impersonate)!

now i get output, just have to fix it. thanks!


----------



## S.T.A.R.S.

FXB said:


> Well my first concern is the UI I'm not sure what to make of it.
> 
> what would be best?
> 
> 1. have a window asking for the customer's name and choice of menu.  From there open a new window displaying the desired menu Then just do a list and add the prices
> 
> or should I do it all in one window?  point my in the right direction



LoL the look of the program and how the controls will look like and be positioned is totally up to you.Just note that in order to make this work you must know how to perform basic mathematical calculations like + , - , * and / using the integer.The keyword is "int".Or even better you can use the "decimal" in order to work with the decimal numbers and make sure that prices are always completely correctly calculated.

I use the C# 2002 programming language,but the logic is the same.VB is even easier.

Just make sure you know how to perform that and as for the look,keep it as simple as possible because NOT ALL people are smart to use more then one window believe it or not lol.Not all of them are programmers


----------



## FXB

S.T.A.R.S. said:


> Not all of them are programmers


I wouldn't call myself a programmer I know very little about programming.


----------



## S.T.A.R.S.

FXB said:


> I wouldn't call myself a programmer I know very little about programming.



Well I am giving instructions to people from C# programming language in order to teach them.I charge 5 dollars per hour.If you want I can teach you the C# programming language either in my appartment or firm if you are here (which is highly unlikely) or online using the Team Viewer software and MSN or Skype.
If you are interested,here is my contact information:

Sellphone number: +385 (0) 918921434
E-mail address: marin.j@hotmail.com

I can show you few things for free,but if you want to really learn,either contact me or buy books and video tutorials.




Cheers!


----------



## FXB

> Well I am giving instructions to people from C# programming language in order to teach them.I charge 5 dollars per hour.If you want I can teach you the C# programming language either in my appartment or firm if you are here (which is highly unlikely) or online using the Team Viewer software and MSN or Skype.
> If you are interested,here is my contact information:
> 
> Sellphone number:             +385 (0) 918921434
> E-mail address: marin.j@hotmail.com
> 
> I can show you few things for free,but if you want to really learn,either contact me or buy books and video tutorials.


Thanks I'll consider it.


Here is what I've done for the UI so far.





Advice or feedback?

How would I get this window to disappear and display the menu?


----------



## tlarkin

zombine210 said:


> Hi!
> i'm trying to write a script to check free disk space on my file server. so far i have this
> 
> 
> 
> i know i'm trying to output too much info in one line, but i'm trying to keep it as simple as possible.
> 
> i'm getting this error"
> 
> 
> i've already rewritten this a few time, still geting the same error



Not to derail this thread, but man you should check out python.  There are modules built in (like millions of them) that you can call functions in scripts to do all sorts of OS level stuff, like checking and reporting free disk space.

Python also runs on every single platform, so if you write it for Windows it will still work on Linux and Mac OS X, with the exception of any actual system commands from that OS you may have to change.


----------



## Troncoso

S.T.A.R.S. said:


> Well I am giving instructions to people from C# programming language in order to teach them.I charge 5 dollars per hour.If you want I can teach you the C# programming language either in my appartment or firm if you are here (which is highly unlikely) or online using the Team Viewer software and MSN or Skype.
> If you are interested,here is my contact information:
> 
> Sellphone number: +385 (0) 918921434
> E-mail address: marin.j@hotmail.com
> 
> I can show you few things for free,but if you want to really learn,either contact me or buy books and video tutorials.
> 
> 
> Cheers!



No lie, giving out your phone number on a public forum is not a good idea. Really neither is e-mail.


----------



## Troncoso

FXB said:


> Thanks I'll consider it.
> 
> 
> Here is what I've done for the UI so far.
> 
> 
> 
> 
> 
> Advice or feedback?
> 
> How would I get this window to disappear and display the menu?




Is that the main form? If so, I believe it would be easier if you created 2 forms on top of the main one that display when the program runs. The first will be this screen, the second will be the menu. Then it'll move to your main form. Just an idea.

As for changing forms. I've not used basic since high school. I couldn't tell you exactly. Just google 'switching forms, vb.net'


----------



## Cromewell

FXB said:


> Well my first concern is the UI I'm not sure what to make of it.
> 
> what would be best?
> 
> 1. have a window asking for the customer's name and choice of menu.  From there open a new window displaying the desired menu Then just do a list and add the prices
> 
> or should I do it all in one window?  point my in the right direction





Troncoso said:


> Is that the main form? If so, I believe it would be easier if you created 2 forms on top of the main one that display when the program runs. The first will be this screen, the second will be the menu. Then it'll move to your main form. Just an idea.
> 
> As for changing forms. I've not used basic since high school. I couldn't tell you exactly. Just google 'switching forms, vb.net'



Agreed, using the main form to hold the user name and let them select dinner or lunch is good. Then when they pick their menu you can open it and let them pick what they want. Yuo could even use 3-4 forms if you wanted: a main screen, a lunch menu, dinner menu and then an invoice form. As for hiding the form and displaying the next it's likely similar to vb6 ( ie: formname.hide()/formname.show() ). The actual way of selecting the form may be slightly differrent than that though, I'm finding a lot of people who are writing what looks like vb6 code in their 2008 VB.NET apps so it's hard to tell the difference.


----------



## S.T.A.R.S.

FXB said:


> Thanks I'll consider it.
> 
> 
> Here is what I've done for the UI so far.
> 
> 
> 
> 
> 
> Advice or feedback?
> 
> How would I get this window to disappear and display the menu?



Please translate that language to english on that picture lol.I am lost xD

Anyway it would be good that on the first form you give the users to simply just choose what they want.If for example they want dinner,just make that after the DINNER button (or any other control you want) is clicked (or whatever event you want to use) that the SECOND FORM for the DINNER and ONLY DINNER is showed and that the user can choose what he/she wants for the dinner from the list of all meals you are offering to them.As for the meals menu,I would recommend using the LIST BOX control or at least the COMBO BOX control.

Tip 1: To add another form to your project,go to the solution explorer,right click your project name and choose ADD ITEMS and from the windows that will open choose Form2.vb (or however it is called in VB 2008 .NET).

Tip 2: Here is the code how to close,dispose,show and hide the form:

CLOSE---> me.Close()
DISPOSE---> me.Dispose(true)
SHOW---> Form2.Show()
HIDE---> Form2.Hide()

Here is the C# version for the SHOW and HIDE:

SHOW:

Form2 blabla=new Form2();
blabla.Show();

HIDE:

Form2 blabla=new Form2();
blabla.Hide();

Tip 3: You may want to show the form to the user as the modal dialog box.That means that the user wont be able to use the previous window in the program as long as the current window is opened.That can sometimes be useful so that the user doesnt do dozens of things on the previous windows accidentaly.Here is how to do that in the Visual Basic:

Form2.ShowDialog()

Tip 4: As for closing the forms,I would rather use "Me.Dispose(true)" because that will close the form and also remove ALL ITS usage from the memory.For the difference of CLOSE which just closes the form window,but does NOT remove it from the memory completely.




Cheers!


----------



## FXB

So heres what I've done.

The main window asks for the users name

then ask which menu he wants either Breakfast or lunch




then if the user clicks on the breakfast button I have a form for the breakfast menu that will appear.





If the user select the lunch menu I have a dedicated form for that as well





As you mentioned the CheckedList Box seems more pratical is there an easy way to switch between the two?


I started writing the code and I can't figure out what these errors are  HELP!


----------



## Troncoso

S.T.A.R.S. said:


> Please translate that language to english on that picture lol.I am lost xD
> 
> Anyway it would be good that on the first form you give the users to simply just choose what they want.If for example they want dinner,just make that after the DINNER button (or any other control you want) is clicked (or whatever event you want to use) that the SECOND FORM for the DINNER and ONLY DINNER is showed and that the user can choose what he/she wants for the dinner from the list of all meals you are offering to them.As for the meals menu,I would recommend using the LIST BOX control or at least the COMBO BOX control.
> 
> Tip 1: To add another form to your project,go to the solution explorer,right click your project name and choose ADD ITEMS and from the windows that will open choose Form2.vb (or however it is called in VB 2008 .NET).
> 
> Tip 2: Here is the code how to close,dispose,show and hide the form:
> 
> CLOSE---> me.Close()
> DISPOSE---> me.Dispose(true)
> SHOW---> Form2.Show()
> HIDE---> Form2.Hide()
> 
> Here is the C# version for the SHOW and HIDE:
> 
> SHOW:
> 
> Form2 blabla=new Form2();
> blabla.Show();
> 
> HIDE:
> 
> Form2 blabla=new Form2();
> blabla.Hide();
> 
> Tip 3: You may want to show the form to the user as the modal dialog box.That means that the user wont be able to use the previous window in the program as long as the current window is opened.That can sometimes be useful so that the user doesnt do dozens of things on the previous windows accidentaly.Here is how to do that in the Visual Basic:
> 
> Form2.ShowDialog()
> 
> Tip 4: As for closing the forms,I would rather use "Me.Dispose(true)" because that will close the form and also remove ALL ITS usage from the memory.For the difference of CLOSE which just closes the form window,but does NOT remove it from the memory completely.
> 
> 
> 
> 
> Cheers!



To avoid confusion of these language threads can you please keep C# in it's own place.


----------



## Cromewell

For your first error, the compiler is saying it doesn't know how to turn a string into a label. You are missing the property you want to set (in this case I believe it is .text)


		Code:
	

You have:
LblSaisieNom = txtSaisieNom.Text
You want:
LblSaisieNom.Text = txtSaisieNom.Text

The second error tells you what you need to do 


		Code:
	

You have:
frmCafeJean.Hide()
You want:
Me.Hide()


----------



## FXB

> The second error tells you what you need to do
> 
> 
> Code:
> 
> 
> You have:
> frmCafeJean.Hide()
> You want:
> Me.Hide()



but then how do specify which form I want to show or hide?


----------



## S.T.A.R.S.

FXB said:


> but then how do specify which form I want to show or hide?



You can show or hide any forms by doing that from any form you want.However you will need to call all those forms and give them different names above the "public Form1" or which ever form you want to use for that.This is the C# example:

Form1 frm1=new Form1();
Form2 frm2=new Form2();
Form3 frm3=new Form3();
public Form1()
{
       //Here is the entire code of your project of course...
}

And now if for example from the Form1 you want to Show,Hide,Close,Dispose or do anything else with any form like Form2 and Form3,just call them and write the property.For example you want to show Form2,but close Form3.To do that,simply write the following code in the event you are using for that:

frm2.Show();
frm3.Close();

NOTE: Once the Form3 is closed,you will NOT be able to open it again using the "frm3.Show();".That is because after the Form3 was closed,it tells to the compiler that it is actually DISPOSED so if you try to open the Form3 again after you closed it,you will get the runtime exception error that says something like CANNOT ACCESS THE DISPOSED OBJECT.That is normal because your application AUTOMATICALLY disposed the Form3 even though you just used the Close(); method.That is kinda cool because at least you do not need to write the code to dispose that too in order to remove it from the memory and make program run faster and better.Pretty cool ha =) ?
Well anyway to again open the "disposed" Form3,just use the following code:

if(Form3.IsDisposed==true)
{
      frm3=new Form3();
      frm3.Show();
}
if(Form3.IsDisposed==false)           //Or simply use the "else" keyword here...
{
     frm3.Show();
}


So this was the C# example,but the way is the same in VB.It's even easier.Just be sure that the "Me" is the keyword for the current form and "this" in the C#.Also its very easy to show any form in VB for the difference of C#.Just write:

Form3.Show()

That will show/open Form3 immediately.To close it,way is the same:

Form3.Close()


I personally do not use VB so try this and if you get an error,let me know what it says.


----------



## Cromewell

Please don't post C# in this thread, I know it's all part of the .NET family but this isn't the place for it. It may confuse someone who is writing in VB.



FXB said:


> but then how do specify which form I want to show or hide?



You use Me to refer to the current form your code is in. You can still refer to the other forms by their name. So:


		Code:
	

Me.Hide()
frmDejeuner.Hide()

Because the code that is executing is in the frmCafeJean form, Me refers to frmCafeJean. In your code for frmDejeuner, Me would refer to frmDejeuner.


----------



## WeatherMan

Okay I'm a bit stuck 



I've got 3 buttons (select your quiz), a label (selection clicked) and a submit button

Here is the code I have at the moment 

    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
        If strGenre = "Music" Then Music_Quiz.Show()
        If strGenre = "Computer Games" Then Computer_Games_Quiz.Show()
        If strGenre = "Movies" Then Movies_Quiz.Show()
        If strGenre = "" Then MsgBox("Please select a quiz!")
    End Sub

As you can see I'd like a message box to appear if nothing has been selected. I was wondering
how I could get this to work with an Else tag

I've tried 

    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
        If strGenre = "Music" Then Music_Quiz.Show()
        If strGenre = "Computer Games" Then Computer_Games_Quiz.Show()
        If strGenre = "Movies" Then Movies_Quiz.Show() Else
	MsgBox ("Please select a quiz!")
    End Sub

and 

    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
        If strGenre = "Music" Then 
		Music_Quiz.Show()
	End If
        If strGenre = "Computer Games" Then 
		Computer_Games_Quiz.Show()
	End If
        If strGenre = "Movies" Then Movies_Quiz.Show() 
	Else
	MsgBox ("Please select a quiz!")
    End Sub

But because 'Else' only covers one submit at a time, my other 2 items (Computer Games)
& (Movies) flag up as Else aswell. 

Is there any way to get Music, Computer Games & Movies to bring up their specific forms and use Else to filter out anything other than them 3 words + bring up a message box?

Surely I'm doing something wrong, I just can't work out what :] 

I've tried adding Else tags each If which didn't work.
If I could do something like If strGenre = "Music" Then Music_Quiz.Show / *strGenre = "Computer Games" Then Computer_Games.Show / strGenre = "Movies" Then Movies_Quiz.Show Else
MsgBox ("Please select a quiz!")

That would do me fine, But sadly it doesn't work like that 

Any advice?

Thanks
Jason


----------



## Cromewell

You have a couple options: If then elseif then else or use a select case.

If strGenre = "Music" Then Music_Quiz.Show()
elseIf strGenre = "Computer Games" Then Computer_Games_Quiz.Show()
elseIf strGenre = "Movies" Then Movies_Quiz.Show() Else
MsgBox ("Please select a quiz!")

or

select case strGenre
case "Music"
Music_Quiz.show()
case "Computer Games"
Computer_Games_Quiz.Show()
case "Movies"
Movies_Quiz.Show()
case Else
MsgBox ("Please select a quiz!")
end select


----------



## WeatherMan

Thanks for that! 

The second option seems to work flawlessly :]

I've now purchased a Visual Basic book to let me learn the language a little better, have another software design class tomorrow morning.

Will be asking my lecturer about this tomorrow but I was wondering If you could help me with a new thing I'm stuck with.

I've changed strGenre from a label to a textbox and it's working with the If & Else tags.

I can click the buttons and it'll bring up my forms, I can clear the textbox and it'll bring up my MsgBox, I can write random letters and it'll also bring up my MsgBox.

The problem is, I've specified when 'StrGenre' = 'Music' (or any other of my buttons), it'll open if I've pressed the button, but not if I type the value in.

Any idea's what's up?  

Edit - Sorted!

All I needed to do was change the variable from "strGenre" to TextBox2.Text :] All working now! Thanks for your help.


----------



## bratsos

Hello world !!!

Can anyone show me some good tutorials in v.b links with live interactivity.
Eg: To go next stage of tutorial, you must pass first this task of current tutorial.


----------



## jllipke

Cromewell said:


> What exactly are you looking for? I won't do your homework but I don't mind helping you with certain aspects of it.
> 
> In this case, it's a relatively simple project so I'd suggest planning out/designing the initial UI that will be presented then slowly building up the backing code and any other UI objects you need to make it work.
> 
> I'm not big on VB2008, the last version I used was 6.


Visual Basic 6 is best


----------



## S.T.A.R.S.

jllipke said:


> Visual Basic 6 is best



They are all the best if you have enough knowledge to use it lol.


----------



## bratsos

Cromewell said:


> Code:
> 
> 
> You have:
> LblSaisieNom = txtSaisieNom.Text
> You want:
> LblSaisieNom.Text = txtSaisieNom.Text
> 
> The second error tells you what you need to do
> 
> 
> Code:
> 
> 
> You have:
> frmCafeJean.Hide()
> You want:
> Me.Hide()




True.
And a small mistake in programming tree, cause many issues.
At least is no logical mistake
Me at programming i make many logical mistakes


----------



## S.T.A.R.S.

bratsos said:


> True.
> And a small mistake in programming tree, cause many issues.


 
Oh yea.I just had a huge bug in my UAC project yesterday which contains TONS of complicated lines and on which I work for about 4 months already.More than 15000 lines in one form.And I had a strange bug which I had no idea why it was happening.At the end after reading ALL the lines with a huge toture (lol) I found out I used wrong string value LOOOOOOOOOOOOOL.It was so damn simple and I got so pissed off for losing so much time on that crappy simple bug lol,but then agian like you say small and simple things can cause many issues.
I really hate programming sometimes


----------



## CrazyMike

Alright guys / gals,

I have recently found myself in a programming predicament. I have never programmed (write code) in any way shape or form before. So this is all new to me. I have been Googling and YouTube-ing as much as i can, and find myself stuck right now. 

Here's what's going on:

So i have created a "Main page" in excel with buttons on it. Each button has it's purpose.

The buttons on the main page:






So when the first three buttons are pushed, a pop up window comes up (something like the following picture:





I cannot figure out what the code would be for the "Submit" button. I need it so when variable value is inputed (in this case serial number) it will open a specific workbook and match the inputed number with the worksheet name in that workbook. Would also like an error to pop up if part number is not found and allow user to retry. As well as close window after done search. 

This next one, i cannot figure out the "Submit" button again. I need the code to input all data into a worksheet in the proper table columns. 





If you notice there is one that is blue, I would like it if when part number is inputed, the description automatically pops up. As well with error code on this one if a field is left blank. 

This last one uses the same data as previous and searches this said table. 






Just type in any of the ONE field, and the search will pop up anything corresponding to that specific search. 


So basically i am looking for any help in creating these codes. Either help/link to better understanding VB in how code is written (specific to my situation) or help writing in general. 

Thanks for your support.


----------



## Cromewell

> I cannot figure out what the code would be for the "Submit" button. I need it so when variable value is inputed (in this case serial number) it will open a specific workbook and match the inputed number with the worksheet name in that workbook. Would also like an error to pop up if part number is not found and allow user to retry. As well as close window after done search.


This isn't how to do it, but just an example I found online of how to search through a worksheet for a specific value. You should be able to modify it to work in your project.


		Code:
	

Sub Find_First()
    Dim FindString As String
    Dim Rng As Range
    FindString = InputBox("Enter a Search value")
    If Trim(FindString) <> "" Then
        With Sheets("Sheet1").Range("A:A")
            Set Rng = .Find(What:=FindString, _
                            After:=.Cells(.Cells.Count), _
                            LookIn:=xlValues, _
                            LookAt:=xlWhole, _
                            SearchOrder:=xlByRows, _
                            SearchDirection:=xlNext, _
                            MatchCase:=False)
            If Not Rng Is Nothing Then
                Application.Goto Rng, True
            Else
                MsgBox "Nothing found"
            End If
        End With
    End If
End Sub

To write a value to a cell you can use


		Code:
	

Worksheets("Sheet1").Cells(x, y) = value

where x is the row and y is the column (both are numbers).


----------



## S.T.A.R.S.

CrazyMike said:


> I have never programmed (write code) in any way shape or form before. So this is all new to me......



If you have never written any programming code before then FIRST forget about thinking to make this to work great in 1 day.
What you need is to start learning programming from the beginning.And when I say BEGINNING,I mean on something like HELLO WORLD application.

You cannot create any good applications/programs if you have never ever written any programming code before.You need to start from the beginning and first learn basic things and write the most simple programming line such as:

MessageBox.Show("Hello World")

Then understand that line and slowly move on and learn more and more.You can either use books,tutorials or other internet resources.

Once you have that knowledge THEN you can create programs to do things you want.You cannot just simply find the code for let's say SUBMIT button and then perform copy/paste and make it work lol.Because if you do,it is NOT going to work properly because that code you copied and pasted could be written for God knows what.And I assure you that the code you will copy and paste will NOT do exactly what you want...it will do something else what the programmer who originally wrote it for 

You need to understand the programming logic well and once you do,you can do whatever you want.So start from the beginning and not from the middle like you do right now.You cannot expect to make that in one day.You first need to learn a lot of things before that.Programming is not so easy as it may seem.
Take a look at the following code example:





You probably don't understand it right? That is why you must learn it well and understand the logic before you are able to create something on your own.If you do simple copy and paste from the above image and paste it into your program,it will NOT work and reasons can be MANY such as:

-the specified control name cannot be found...
-assembly reference...
-method that is being used cannot be found...
-DLLs (if any)...
-events that are not created...
-string and other values you use were not declared...
-and MUCH more...

So you cannot just take the code and use it immediately.It will simply not work if you do not know and understand what you are doing.First start from something simple like HELLO WORLD programs and then move on step by step.





Cheers!


----------



## CrazyMike

Thank you guys so much. I do understand somewhat of the code. Like the example you have given S.T.A.R.S, i understand portions of the code "Hello World". Nowhere near understanding all of it.

The code that Cromewell has provided helps me out so much. I was mainly confused of the starting of the code, and the example he has given me helps me out on where to start. Thanks.

I'm actually in the market of a book to further understand VBA. It's going to take me time but i think ill get it figured out.

If either of you know a good book or online training that could help me learn the language of VBA, please let me know . Much like the example S.T.A.R.S has given with the "hello world", but goes further in depth. 

Thanks again!!


----------



## S.T.A.R.S.

This is exactly what you need:

http://www.amazon.com/Microsoft-Pro...9005/ref=sr_1_1?ie=UTF8&qid=1327164562&sr=8-1


All the things you learn from that book can also be applied for newer VB 2010.It can of course also be applied in older VB such as 2002 and 2003 and 2005,but in VB 2002 and probably 2003 it might require some extra code to be written in order for examples from that book to work.But don't use VB 2002 and 2003.They are old.Feel free to use VB 2010 for this book.



Cheers!


----------



## CrazyMike

S.T.A.R.S. said:


> This is exactly what you need:
> 
> http://www.amazon.com/Microsoft-Pro...9005/ref=sr_1_1?ie=UTF8&qid=1327164562&sr=8-1
> 
> 
> All the things you learn from that book can also be applied for newer VB 2010.It can of course also be applied in older VB such as 2002 and 2003 and 2005,but in VB 2002 and probably 2003 it might require some extra code to be written in order for examples from that book to work.But don't use VB 2002 and 2003.They are old.Feel free to use VB 2010 for this book.
> 
> 
> 
> Cheers!



It says 2008? Anyway, if you say it will help for the 2010 version, I'm on my way to the store to pick it up  Thanks for the suggestion.


----------



## CrazyMike

Hey guys/gals

I am learning how to code in VBA while doing up a project. I went to pick up a few books and reading while practicing. Basically i just need to help to figure out whats going on.

Scenario:

I have a form that i am inputting info into a separate workbook/worksheet. So the user clicks on a button, form pops up, they input all the information, and the information clears after submitting (with all info inputted into the workbook/worksheet specified). 

The following is the code i came up with:



		Code:
	

Private Sub cmdcancel_Click()
Unload frmcompletedsealinput
End Sub

Private Sub cmdsubmit_Click()
    Dim iRow As Long
    Dim ws As Worksheets
    Dim wb As Workbook
    Set wb = Workbooks("")
    Set ws = Worksheets("Sheet1")

    'Find Last Row in table
    iRow = ws.Cells.Find(What:="*", SearchOrder:=xlRows, _
    SearchDirection:=xlPrevious, LookIn:=xlValues).Row + 1
    
    'check for a Job Number
    If Trim(Me.txtjobnumber.Value) = "" Then
    Me.txtjobnumber.SetFocus
    MsgBox "Please enter a job number"
    End If

    'check for a Serial Number
    If Trim(Me.txtserialnumber.Value) = "" Then
    Me.txtserialnumber.SetFocus
    MsgBox "Please enter a Serial Number"
    End If

    'check for a Date
    If Trim(Me.txtdate.Value) = "" Then
    Me.txtdate.SetFocus
    MsgBox "Please enter a Date"
    End If
    
    'check for a Seal Part Number
    If Trim(Me.txtsealpartnumber.Value) = "" Then
    Me.txtsealpartnumber.SetFocus
    MsgBox "Please enter a Seal Part Number"
    End If
    
    'check for a Customer Name
    If Trim(Me.txtcustomername.Value) = "" Then
    Me.txtcustomername.SetFocus
    MsgBox "Please enter a Customer Name"
    End If
    
    'check for a Location
    If Trim(Me.txtlocation.Value) = "" Then
    Me.txtlocation.SetFocus
    MsgBox "Please enter a Location"
    End If
    
    'Copy data to the Completed seal table
    wb.ws.Cells(iRow, 2).Value = Me.txtsealpartnumber.Value
    wb.ws.Cells(iRow, 3).Value = Me.txtserialnumber.Value
    wb.ws.Cells(iRow, 4).Value = Me.txtcustomername.Value
    wb.ws.Cells(iRow, 6).Value = Me.txtjobnumber.Value
    wb.ws.Cells(iRow, 7).Value = Me.txtdate.Value
    wb.ws.Cells(iRow, 9).Value = Me.txtlocation.Value
    
             'Reset data for another entry
            Me.txtsealpartnumber.Value = ""
            Me.txtserialnumber.Value = ""
            Me.txtcustomername.Value = ""
            Me.txtjobnumber.Value = ""
            Me.txtdate.Value = ""
            Me.txtlocation.Value = ""
    
End Sub


In this code there are several things; wb values, ws value. a formula/code to find the last availiable line in table, input codes, empty slot error codes and clear codes. 

When i try out this code, the form pops up, i input data, click the submit button, but nothing pops up. Just goes back to my code and highlights "
Private Sub cmdsubmit_Click()". No data was entered in the workbook/worksheet. 

just wanted to know if anyone can take a look at this and see where i could possible going wrong or doing wrong (*besides everything lol*).

Thanks


----------



## CrazyMike

Just wanted to bump this back up..... see if anyone can help.


----------



## Cromewell

If it's jumping to code there's usually a runtime error. I'm guessing this line: Set wb = Workbooks("") is the problem.

What version of excel are you using?


----------



## CrazyMike

Cromewell said:


> If it's jumping to code there's usually a runtime error. I'm guessing this line: Set wb = Workbooks("") is the problem.
> 
> What version of excel are you using?



2010..... Do you think it's the file name? Maybe i am entering it wrong? Do you include the "xlsx"?



Also, i messed up in copying that code. actual code in the beginning is:



		PHP:
	

    Dim iRow As Long
    Dim wb As Workbook
    Set wb = Workbooks("Completed Seals 2012")
    Dim ws As Worksheets
    Set ws = Worksheets("Sheet1")


----------



## Cromewell

Yes you need the extension. If it's not in the current directory you might need to qualify the path as well.


----------



## CrazyMike

Cromewell said:


> Yes you need the extension. If it's not in the current directory you might need to qualify the path as well.



hmmm tried it with the xlsx... still nothin. What do you mean by " If not in the current directory" ?


----------



## Cromewell

I think it will be the directory that your excel file is, although I think vbs defaults to 'My Documents' if you don't put the full path in. VBA may be similar.

Are you trying to open the workbook you are currently in? You might be able to just reference the sheet names instead of the workbook.


----------



## S.T.A.R.S.

To open the file which is not in the current application's folder/directory,you must give it the fully qualified path including the file and it's extension.For example:

C:\VB projects\My project\Book.xlsx


----------



## CrazyMike

awesome.... will give that a try


----------



## CrazyMike

S.T.A.R.S. said:


> To open the file which is not in the current application's folder/directory,you must give it the fully qualified path including the file and it's extension.For example:
> 
> C:\VB projects\My project\Book.xlsx



This didn't work. Comes up with an error if i type in a file location such as:

Workbooks = Workbooks( C:/users/name/documents/documentname)

Know any other good books or turtorials that would have what i am looking for? lol

Can't believe I'm stuck like this.


----------



## S.T.A.R.S.

Usually the path is written between the QUOTES and therefore you must also use double slash ---> \\


----------



## Matt

Has anyone tried BBCBasic?  BBC Basic For Windows (BB4W) is an increadibly comprehensive and easy to use programming language, and it's easy to understand when it's written down.  There's a free demo you can try at http://www.bbcbasic.co.uk/bbcwin/bbcwin.html

I've been using it - or it's predecessors - for the past thirty years.  Every time I come up against a problem that seems to be insurmountable, a solution is always forthcoming.

It's just a suggestion, but I'd be interested to see what others think.

Matt


----------



## bmigga

Got a question for you guys. Very (should be) easy coding. I have to write an IF statement that does the following: (I am VERY VERY new to VB)
---
a)	If the LessonType is “Voice” then display the LessonType field value in a bold, blue font (FontBold = True, ForeColor = vbBlue).
---  
b)	Otherwise, display in normal, black font (FontBold = False, ForeColor = vbBlack) for all other values. 
--- 
Could you tell me if I have it close?
---
       If LessonType = "Voice" Then
           LessonType.FontBold = True 
           LessonType.ForeColor = vbBlue
       Else
           LessonType.FontBold = False
           LessonType.ForeColor = vbBlack
       End If


----------



## bmigga

Once again, I am VERY new to Visual Basic. & Obviously the indentions aren't right. (Couldn't do them on this forum)


----------



## Troncoso

It's been too long since I've used VB, so I don't remember the syntax, but as a tip, when you post code use the [ CODE ][ /CODE ] brackets to keep the formatting (without the spaces):

So:



		Code:
	

If LessonType = "Voice" Then
	LessonType.FontBold = True 
	LessonType.ForeColor = vbBlue
Else
	LessonType.FontBold = False
	LessonType.ForeColor = vbBlack
End If


----------



## S.T.A.R.S.

VB:

If LessonType = "Voice" Then
    LessonType.FontBold = True 
    LessonType.ForeColor = vbBlue
Else
    LessonType.FontBold = False
    LessonType.ForeColor = vbBlack
End If


C#:

if(LessonType=="Voice")
{
LessonType.FontBold=true;
LessonType.ForeColor=vbBlue;
}
else
{
LessonType.FontBold=false;
LessonType.ForeColor=vbBlack;
}




Cheers!


----------

