Shoutbox

Argh Visual Basic - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Skype & Technology (/forumdisplay.php?fid=9)
+---- Forum: Tech Talk (/forumdisplay.php?fid=17)
+----- Thread: Argh Visual Basic (/showthread.php?tid=39470)

Argh Visual Basic by Wabz on 03-03-2005 at 07:02 PM

I'm stuck again.  I'm attempting to make something which displays timetables 1-12 .

So it would display like this

1 * 1 = 1    2 *1 = 1
1 * 2 =2     2 *2 = 2
1 * 3 =3     2 *3 = 6

Any sugguestions I've really had enough everything i try just breaks.

Its the second thing I'm struggling with :'(


RE: Argh Visual Basic by CookieRevised on 03-03-2005 at 07:35 PM

The question/problem is to vague though. I could post the code to generate those tables, but it highly depends on exactly how you want to display them and where you want to display them...

In essence it will just be some simple nested FOR...NEXT loops.


It would be better if you attach your code, so it can be fixed in the way you need it.


RE: Argh Visual Basic by Wabz on 03-03-2005 at 07:40 PM

K Cookie well I'll try and make some sense of it myself to make it sort of work before i even post it

[edit]  This is actually way harder than I thought , basically all I need to do is have all the times tables print to a form.  on the click of a command button.  I'm reading up on something called tabs at the moment I don't know if this is the way to go but it seems to look hopeful


RE: Argh Visual Basic by CookieRevised on 03-03-2005 at 07:44 PM

In essence it would be something like:

code:
For TimesTable = 1 to 10
   For Number = 1 to 10
      Debug.Print Number & " x " & TimesTable & " = " & (Number * TimesTable)
   Next Number
Next TimesTable

;)
RE: Argh Visual Basic by Wabz on 03-03-2005 at 07:47 PM

Well that worked :D

I'm sort of trying to teach myself Vb too fast I think and I keep falling over.

[edit]  Got it to print to a form now :D  Just need to tidy them into rows Any ideas [/edit]

code:
Private Sub cmdcalc_Click()


    Dim Timestable As Integer
    Dim Number As Integer

    For Timestable = 1 To 12
        For Number = 1 To 12
            frmTables.Print Number & " x " & Timestable & " = "; (Number * Timestable)
        Next Number
    Next Timestable
   
   
End Sub

Never ever did one think he would use that bbcode
RE: Argh Visual Basic by Dempsey on 03-03-2005 at 08:09 PM

to make it go into rows just add a vbcrlf like

code:
Private Sub cmdcalc_Click()


    Dim Timestable As Integer
    Dim Number As Integer

    For Timestable = 1 To 12
        For Number = 1 To 12
            frmTables.Print Number & " x " & Timestable & " = "; (Number * Timestable) & vbcrlf
        Next Number
    Next Timestable
   
   
End Sub

RE: Argh Visual Basic by Wabz on 03-03-2005 at 08:19 PM

That just spaced them out :S 

Thanks for the input its starting to look better :D

Right I think its got to be the tab command some how pushed into this :S

I'm getting there slowly


RE: Argh Visual Basic by Dempsey on 03-03-2005 at 08:41 PM

ah yea, i see what u mean, i just tested the code,  so u want each time table set in a new column? 


RE: Argh Visual Basic by Wabz on 03-03-2005 at 08:46 PM

quote:
Originally posted by Dempsey
ah yea, i see what u mean, i just tested the code,  so u want each time table set in a new column?


Yup :D

I've been coding for nearly 7 hours now on and off.  Its harder than it looks I dunno how major coders do it
RE: Argh Visual Basic by Dempsey on 03-03-2005 at 08:51 PM

once you get into it  its not too bad.  But about the columns, printing it onto the form i cant think of a way to put it in columns, not saying it cant be done, i just cant think how atm


RE: Argh Visual Basic by matty on 03-03-2005 at 09:02 PM

You could try using vbNewLine to create a newline

code:
Private Sub cmdcalc_Click()

    Dim Timestable, Number As Integer

    For Timestable = 1 To 12
      For Number = 1 To 12
        frmTables.Print Number & " x " & Timestable & " = " & (Number * Timestable) & vbNewLine
      Next Number
  Next Timestable
End Sub

RE: Argh Visual Basic by Wabz on 03-03-2005 at 11:28 PM

Thanks Matty but that didn't do it either  I worked out theres a tab command that can list the tables in columns which goes tab(10)  but i dont understand the use of it exactly


Heres the source I currently have for it www.likethat.org.uk/tables.zip


RE: Argh Visual Basic by segosa on 03-04-2005 at 12:04 AM

use Chr(10)


RE: Argh Visual Basic by Wabz on 03-04-2005 at 01:09 AM

Huh where?  It wont work where i think its supposed to go :S


RE: Argh Visual Basic by matty on 03-04-2005 at 01:53 AM

code:
Private Sub cmdcalc_Click()

    Dim Timestable, Number As Integer

    For Timestable = 1 To 12
      For Number = 1 To 12
        frmTables.Print Number & " x " & Timestable & " = " & (Number * Timestable) & CHR(10)
      Next Number
  Next Timestable
End Sub
OR

code:
Private Sub cmdcalc_Click()

    Dim Timestable, Number As Integer

    For Timestable = 1 To 12
      For Number = 1 To 12
        frmTables.Print Number & " x " & Timestable & " = " & (Number * Timestable) & CHR(10) & CHR(13)
      Next Number
  Next Timestable
End Sub

RE: Argh Visual Basic by XM4ST3RX on 03-04-2005 at 02:34 AM

Hi,

I dunno if this will make it more tidier and easier for you to use.
It's using a listbox, and it sections off each times table.

When you click on a certain times table, it shows each corrosponding equation in the second listbox.

I've uploaded the source anyways, so check it out.
Hope it helps.


Kind Regards,
XM4ST3RX


RE: Argh Visual Basic by CookieRevised on 03-04-2005 at 09:09 AM

If you want to directly write/print to a form, you must take in account the type of font you're using. Normal/default fonts are not proportional (just like on this forum). This means that even if you put a tab character between your columns, the columns wouldn't be aligned properly and you will get this:

1 x 1 = 1         1 x 2 = 2         1 x 10 = 10         1 x 12 = 12
2 x 1 = 2         2 x 2 = 4         2 x 10 = 20         2 x 12 = 24
3 x 1 = 3         3 x 2 = 6         3 x 10 = 30         3 x 12 = 36
...
8 x 1 = 8         8 x 2 = 16         8 x 10 = 80         8 x 12 = 96
...
10 x 1 = 10         10 x 2 = 20         10 x 10 = 100         10 x 12 = 120

the columns aren't aligned.

So using tab characters to space your columns like this is almost always not advisable, just as to print directly to a form is almost always not advisable for the above reason. Also, printing 12 columns near each other will make your form very wide and inpracticle. A possible solution is the one shown by XM4ST3RX. This also shows that it is far better to not print directly to a form, but to a control. In the case of XM4ST3RX's code it are two listboxes.

To show what you want in theory, you could use a multiline textbox with a proporional font (eg: courier new) and using spaces to align the columns.

A bit more advanced would be to set tabstops in a control (listbox or textbox or whatever) and use the tabcharacter to align the columns. Setting tabstops must be done by calling an API; something you're not ready yet to use I assume :)

Anyways, here is the code to print all your columns side by side into a multiline textbox and using spaces to align the columns:

PS @ XM4ST3RX:
Do NOT do:
    Dim TimesTable, Number as integer
This will NOT declare TimesTable as an integer, but as a variant! Always seperate your declare statements to avoid such errors:
Dim Number As Integer
Dim TimesTable As Integer


RE: Argh Visual Basic by Wabz on 03-04-2005 at 01:36 PM

Thanks Guys, after all that I was in a lecture today and he basically shown us how to do this.  :@

Great help.  I can get on with the next one now TictacToe, control arrays :S


RE: Argh Visual Basic by siebe on 03-04-2005 at 02:08 PM

quote:
PS @ XM4ST3RX:
Do NOT do:
    Dim TimesTable, Number as integer
This will NOT declare TimesTable as an integer, but as a variant! Always seperate your declare statements to avoid such errors:
Dim Number As Integer
Dim TimesTable As Integer

Dim Number As Integer, TimeTables As Integer
Is fine too :) As long, like you said, each var carries a datatype
RE: Argh Visual Basic by Mike on 03-04-2005 at 02:15 PM

quote:
Originally posted by Wabz
Thanks Guys, after all that I was in a lecture today and he basically shown us how to do this.  :@

Great help.  I can get on with the next one now TictacToe, control arrays :S
So anyway, what did they tell you to do?


RE: Argh Visual Basic by Dempsey on 03-04-2005 at 02:25 PM

quote:
Originally posted by Wabz
control arrays :S
Yea control arrays can seem confusing but once you start using them they can be great they can reduce the amount of code you need by loads.

A mate at college is making Tioc tac Toe for one of his assignments and he didnt use control arrays and hes got loads and loads of uneeded code, if he'd used arrays it could have been about a tenth of the code.
RE: Argh Visual Basic by Wabz on 03-04-2005 at 02:44 PM

Yeah i worked out I can do it with Arrays and command buttons

The problem is firstly getting the box to display X or O depending on a radio button.  Once thats been done its just a series of if statements with all possible winning combinations, one to say if all the squares all fun its a Draw, and one to say change player and have another go