Fusion Universe
October 17, 2018, 08:36:11 pm
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Forum Launched
 
  Home Help Search Arcade Gallery Staff List Login Register  
  Show Posts
Pages: [1] 2
1  Tutorials / Visual Basic 6.0 / Coding a calculator Calculator on: August 08, 2008, 12:37:33 pm
hey, there are loads of ways to code a calculator, but i do it this way, so i dont want to have a talk so lets begin

have an form with the following buttons and text box: (btw, i forgot to add the "+" button on this image, sorry!


I dont care how you call your calculator and what you enter as start value in the textbox

well, double-click on the button with number 1 on it.
now, write the following code: (btw, i assume you take '0,' as starting value)

If Text1.Text = "0," Then Text1.Text = "1" Else Text1.Text = Text1.Text + "1"

explination of the code:
if ( start for asking a question )
text1.text = "0," (the question itself)
then (if value question is true, then it will do the following expression)
text1.text = "1" ( the If True expression )
else (if question asked is false, it performs the following expression)
text1.text = text1.text + "1"

or in other words, this code makes the text "1" if the textbox is "0,"

do the same with all other 8 buttons with the numbers, but replace the number "1" with the value of the button
with the zero button, add this code:
If Not Text1.Text = "0," Then Text1.Text = Text1.Text + "0"

now we set-up our values, so lets make it do stuff
but for this, we need a module
make a module, and add the following code
Global reminder1 As String
Global reminder2 As String
global changer as string
global answer as string

you can also do a private reminder, but i am at this moment to lazy what the simple codes for that are.

now, lets code the rest
now, lets make the devide buttons first ( the slash "/" )

changer = "/"
If Not Val(Text1.Text) = "0" Then reminder1 = Val(Text1.Text) Else MsgBox "Incorrect divide value!!", vbInformation, "Error"
If Val(Text1.Text) = "0" Then changer = ""
Text1.Text = "0"

now, lets make the "=" button work for the slash "/"

If changer = "/" Then GoTo divide
Exit Sub
divide:
If Val(Text1.Text) = "0" Then MsgBox "Incorrect divide value!!", vbInformation, "Error"
If Not Val(Text1.Text) = "0" Then
reminder2 = Val(Text1.Text)
answer = reminder1 / reminder2
Text1.Text = answer
reminder1 = Text1.Text
End If
End Sub

now try it
i wont explain the code, because its better to find out yourself how this code works

now, with that, i want that when i press clear, my screen is 'clear'
so simple, add this code to that button
reminder1 = ""
reminder2 = ""
changer = ""
text1.text = "0"

now, with that, lets start coding the * (multiply ) button by editing its buttons code
changer = "*"
reminder1 = Val(Text1.Text)
Text1.Text = "0"

now, again, lets edit the = button so we have the following code:
If changer = "/" Then GoTo divide
If changer = "*" Then GoTo multiply
Exit Sub
divide:
If Val(Text1.Text) = "0" Then MsgBox "Incorrect divide value!!", vbInformation, "Error"
If Not Val(Text1.Text) = "0" Then
reminder2 = Val(Text1.Text)
answer = reminder1 / reminder2
Text1.Text = answer
reminder1 = Text1.Text
End If
Exit Sub
multiply:
reminder2 = Val(Text1.Text)
answer = reminder1 * reminder2
Text1.Text = answer
reminder1 = Text1.Text
end sub

now try it, they both work
(btw, if you would code a little more, you can have an exact copy of the options as windows calculator, but we arent doing that so)
now, the both work, lets continue with the - and + buttons
the - button and + button:
"-"
changer = "-"
reminder1 = Val(Text1.Text)
Text1.Text = "0"

"+"
changer = "+"
reminder1 = Val(Text1.Text)
Text1.Text = "0"

and once again, lets edit the = button till you got the following code:

If changer = "/" Then GoTo divide
If changer = "*" Then GoTo multiply
If changer = "-" Then GoTo min
If changer = "+" Then GoTo plus
Exit Sub
divide:
If Val(Text1.Text) = "0" Then MsgBox "Incorrect divide value!!", vbInformation, "Error"
If Not Val(Text1.Text) = "0" Then
reminder2 = Val(Text1.Text)
answer = reminder1 / reminder2
Text1.Text = answer
reminder1 = Text1.Text
End If
Exit Sub
multiply:
reminder2 = Val(Text1.Text)
answer = reminder1 * reminder2
Text1.Text = answer
reminder1 = Text1.Text
Exit Sub
min:
reminder2 = Val(Text1.Text)
answer = reminder1 - reminder2
Text1.Text = answer
reminder1 = Text1.Text
Exit Sub
plus:
reminder2 = Val(Text1.Text)
answer = Val(reminder1) + Val(reminder2)
Text1.Text = answer
reminder1 = Text1.Text

End Sub

now try your calculator,
after testing the calculator now should work ( i made this tutorial along with the calculator , so everything is tested by me )

you now got a basic calculator, and you can find out the rest yourself, at least, i guess xD
2  Rules and anouncements / REGISTER / Register - Welcome on: August 08, 2008, 08:03:01 am
yo, all new guys, be a part of our community, and join open projects, create tutorials, and be a man ( or woman Tongue )
sorry, i dont know if i should post this, because its actualy spam
3  Miscellaneous / Introduce yourself / Re: Hi, I'm cenarius on: August 08, 2008, 04:27:22 am
Tongue, with our new advanced html website, there must be no bugs xD,

it doesnt matter that you arent a programmer or something, thats why this forum excists, this forum is for all people who wish to learn professional  things, like photoshop, c++,visual basic, 3d modeling maybe ^^
4  Tutorials / Visual Basic 6.0 / Coding basic loops or costum loops on: July 30, 2008, 04:59:42 am
Yo, welcome to my coding tutorial for visual basic 6.0
in this tutorial i will learn you how to loop on serveral ways

lets start with simple coding functions

well, for almost every code, you use an variable, so lets start with that

dim str as string

ok, i wrote this, what does it mean?

dim = dimension, dunno why its called dimension, but thats not crucial to know. This word gives the accessibility for the variable. ( how larger the value, how more space it will take in the memory )

str = the variables name, you can change it to everything you want it to be, as long as there are no spaces
as string = defines it as a string, there are loads of those variable types in visual basic, like listed below:
Double
long
integer
byte
currency
boolean
string
variant
Object

so, what are all those variable types?
double = can hold from -1.79769313486232E+308 to 1.79769313486232E+308
long = can hold values from -2,147,483,648 to 2,147,483,647  ( and for advanced users: its 32-bit )
integer = can hold values from -32768 to 32767 ( 16-bit )
byte = can hold values from 0 to 255 ( 8-bit )
currency = can hold values from 922,337,203,685,477.5808 to 922,337,203,685,477.5807 ( Dollars ), it changes depending your currency settings.
boolean = has only 2 values, TRUE and FALSE, in binairy, it would be 1 and 0 , these words are reserved and cannot be used for itemnames etc.
string = a string can hold 0 to 65,400 characters, including symbols and numbers.
variant = can hold any data of every type, is mostly used for handling unknown variable types and values
Object = A special datatype that holds and references objects such as controls and forms

so, now we know that, we can start doing things and lets start with giving of values.
(DO NOT FORGET TO ADD A LABEL AND THE FOLLOWING CODE TO A COMMAND BUTTON)

Dim str As String
Dim B250 As Byte
Dim CU As Currency
Dim yesno As Boolean
Dim lung As Long
Dim cheese As Double
Dim intt As Integer
Dim var As Variant

'now, lets give them a value, by using a integer generator code, named random
str = Rnd(10)
B250 = Rnd(10)
CU = Rnd(10)
yesno = Rnd(1) ' it cant handle a higher value then this
lung = Rnd(10)
cheese = Rnd(10)
intt = Rnd(10)
var = Rnd(10)
Label1.Caption = str & vbNewLine & B250 & vbNewLine & CU & vbNewLine & yesno & vbNewLine & lung & vbNewLine & var & vbNewLine & cheese & vbNewLine & intt & var

now, look at the values, and notice, that variable types "byte" and "long" are rounded to a complete value.
the rest do all contain a non-rounded value.

so, with that, lets start basic functions

lung = 5
simple code, lung is the defined variable (long), = makes it equal to 5 ( the value )

lung = rnd(5) + 2
lung is again, the defined variable, but rnd(5), generates an random value, + ( means, it will add the next value ) 2, the last integer value.

now, we know how that works, so lets loop it
'our variable integer name is intt
for intt = 0 to 5
next intt
'for means, for that variable, ( this case intt ), the starting number is zero, and it will loop till it reaches 5.
'next intt means, it adds + 1 to intt, which is the first loop, 0

lets make a loop, that loops till it reaches our byte variable b250
b250 = rnd(20)
for intt = 0 to b250
next intt
'basicly, it now loops, till it reaches the value of b250, which is a random value.
now, lets add commands to it, which is in this case, it generates 5 diffrent values in label1 for our double variable named cheese

'label1.caption = "" 'clearing the label first, from any text
for intt = 0 to 5
cheese = rnd(100)
label1.caption = label1.caption & cheese & vbnewline
next intt
'this basicly does 10 actions, 5X rnd(100), and 5X changing label caption
'label1 = our label, cheese is our variable, & vbnewline makes new text starting on a new line

this way, you can create a value generator, which generates multiple values.

another way to loop (not recommend), is to custom loop

intt = 0
startloop:
cheese = rnd(100)
label1.caption = label1.caption & cheese & vbnewline
intt = intt + 1
if not intt = 5  then goto startloop
'startloop is our new label defined, see it as a reference point. same following actions for the looping
'intt = intt + 1 basicly adds everything when the value isn't equal to 5
'if not intt = 5 then goto startloop , if not ( asks a question, if the following expression is true or false )
'intt = 5 ( the expression) , then goto startloop ( the action, goto startloop, makes the program going to startloop label we defined)

so, if i don't recommend, why should i use the the second way?
well, it runs much slower then the first way, and maybe needs more memory to work, but an advantage of it is that you can customize this loop, by referring to another point, when a value is smaller, equal, or larger then you want.
here is a sample

Private Sub Command1_Click()
dim secondway as byte
for intt = 0 to 100
startloop:
secondway = rnd(100)
if secondway > 100 then goto exit:' > means bigger then
if intt < 100 then goto startloop ' < means smaller then
if intt = 100 then label1.caption = "no"
exit sub ' this does the same as end sub, but you can use it this way, or you can use it as errorhandler
exit:
label1.caption = "yes"
end sub

now, we let the program choose yes or no, depending if variable secondway becomes 100

greetz, sunreal fusion universe
FuT, Fusion universe Tutorials
5  Rules and anouncements / REGISTER / Take your time to register on: July 30, 2008, 04:19:54 am
you can see much more of the forum when you register.
still stick to the rules:
you can register here

http://fusion.freesmfhosting.com/index.php?action=join
6  Artwork and projects / Video's / Re: Glitches In some Games ( Very Funny) on: July 30, 2008, 03:57:57 am
its funny, but its not made by you Tongue,
if it was made by you, or at least uploaded by you, you where allowed to post it.
plz, upload yourself, and change the link
7  Artwork and projects / Video's / Re: MCroll'd on: July 30, 2008, 03:54:01 am
LOL!!!!!
this is really funny xD
8  Miscellaneous / Introduce yourself / Re: Howdy Hi, I am BarryMCrolld on: July 30, 2008, 03:41:09 am
yo friend  Roll Eyes
welcome to the forum, while i am posting this, dont expect much from it now xD,
just enjoy the things we have Cheesy
9  Tutorials / Adobe Photoshop CS3 / photshop Cs3 The layout on: July 29, 2008, 10:48:54 am
Yo Yo and hello, welcome to this very first basic tutorial about photoshop cs3.
i will explain the photoshop layout as far as necessary to understand the layout

lets start  Cheesy Cheesy

lets start with the toolbar of tools  Grin

This toolbar contains all tools you need for:
erasing,
moving,
removing,
magnifying,
constructing,
coloring,



that basicly does every usefull tool
this is used very much, because this is the tools for creating all pictures,
without this, people would impossible create a picture.



The channel tab, next to "layers" tab, is for disabling certain basic colors
the colors are:
Red, Green and Blue
This way, you can create a red image grey, a blue sky grey, and grass grey.

Well, this is usefull when working zoomed, you can see your result in small.

BTW, not much photoshoppers have noticed this: the zoomer
here is the last thing you have to know, you will use it alot.
under filter, you can select various kind of options, you should look for it.
under image, you can bring adjustments, and resize canvas and image boundries
under edit, you can find various options, like, rotating, mirroring, scaling, define new patterns etc.

well, the rest is up to you! happy photoshopping
10  Tutorials / Visual Basic 6.0 / Hello World Tutorial on: July 29, 2008, 07:35:47 am
I see loads of hello world tutorials, but they are only saying such small things, so i will post an hello world tutorial, bit more advanced then others.

lets start!! Grin Grin

have a new project + 1 form ready:

after that, create 2 objects.
1 command button : with text: I am here!
1 label , with no text ( or on form load, label1.caption = "" )

have it somewhat like this:

now, here comes the code:
double click on the command button
then write the following code:
(btw, everything with an ' before it, is a comment)

dim hw as byte
hw = Rnd(1) ' this basicly sets the byte hw to either 1 or 0 ( like an boolean )
'rnd(number) means that the program will generate numbers between 0 and the value you enter in number

'now we do a value check
if hw = 0 then label1.caption = "Hello there!!" else label1.caption = "yo!"

'basicly, you now are asking a question: if hw = 0 "the question", then do, caption = "hello there!!",
'if that question has not the answer we are looking for, then its value is false, and you can use an else action:
'caption = "yo"

ok, this is our code

dim hw as byte
hw = Rnd(1)
if hw = 0 then label1.caption = "Hello there!!" else label1.caption = "yo!"


ok, press F5 or the blue arrow, and TEST if it works!
the result will be, that if you press the button multiple times, it will display another text.

now, i want that in the second message, it also gives the current time and date, there are multiple ways to get it, but i do the following:

instead of
else label1.caption = "yo!"
replace it with
else label1.caption = "man, today its " & Now()
'now() is a time format, it gets the current date and time
this will display : man, today its "current time"

after you press multiple times now, you will see, "Hello there!!!", and "man, today its 'current date'"

that was my hello world tutorial


sunreal, fusion universe
FuT, Fusion universe Tutorials
11  Tutorials / Visual Basic 6.0 / The Layout on: July 29, 2008, 06:36:03 am
Hi, welcome to this visual basic 6.0 tutorial about the layout.
Lets start opening a project by
 clicking File-->> New Project

It will bring you a dialog of various kinds of program intentions:
Standard EXE ::> Simple, what you program is what you see, requires windows only
ActiveX EXE ::> This program acts like an activeX DLL, but has its own workingspace (Dunno how to explain this very well)
activeX DLL ::> What it says, its a dinamicly linked library, but supports COM, which means "Component object model"
activeX Control ::> (I never use ActiveX, so i cant really tell what control does) ActiveX controls control the gathering the information for applications that work over the internet.

I never used the rest, xD, so i cant list more,

lets continue with the standard EXE by selecting it, and pressing OK.
Now, All kinds of things are popping up, project1-form1 window, Tools and controls, properties menu etc.
well, lets have a look at the general tools:
Simple yet effective, The pointer
Used for selecting controls in forms, such as buttons, textboxes, listboxes and imageboxes etc.

The picturebox
This control is used for loading pictures into your program

The label
A object that will be and is used very much, probably almost all visual basic programs contain at least 1 label
this object can hold various characters and signs.

The Textbox
This tool is probably along with the command button the most used object in visual basic.
It allows the program to read text from the textbox, whatever the user of the program has entered.
From a value, till a story.

The frame
Its used to seperate objects and controls from an area in a form.Is also used in combination of tabs.

The button
This control is likely the most used in visual basic, there is probably no program without it.

The checkbox
Its actualy an boolean control, checked = on ( true ) unchecked = off ( false )

The radiobutton
Can be used to make selections, you need to explore this control to know what to do with this

The combobox
Its the same as an droplist, but you can change the text

The listbox
This is a list, simple, yet effective

The timer
Also a well-known object for timing functions, good for checking time, calculate repeatable stuff,  etc.
also used alot

This where all basic controls, which are also used alot.


This is our form, i added some controls to it, and gave it a color for background.

another thing to know, is the properties menu.
This tool will be used alot when editing controls and objects


Name : "is the objects name used for coding of the programmer"
Backcolor : "Is the color on the background"
Enabled : "When program is active, can the button ( in this case ) be clicked"
Font: "What it says, the text display font of the button"
Height: "The buttons height"
Width: "The buttons Width"
Left : "how far away is the button from the leftside"
Mouse-pointer: "The icon that the program will give when mouse-over the button"
Picture: "when style is set to grapical, the gray color turns into the picture you uploaded to your program"
Style: "Style has 2 options, Standard:graphical ,  Standard = standard grey and black etc, graphical is costimizeable"
Tabindex: "determinate what the rank is when pressing TAB key( when program is active )"
Tooltiptext: " when mouse-over the button, after a few seconds it will show this text"
Top: "How far away is the button from the topside"
Visible: "Is the button visible or not when running the program" ( True = visible )

I skipped some which are listed above in the picture, but i am no god either, i dont have all time and knowledge of the world.

So, after you learn how to use these things, you can add codes, simple, by double clicking on the object or form.
then you get the following window:


where "load" is located, thats the place when the button does that function:
why do they do that?, its because when this form loads, it will perform the actions in the coding area.
But, imagine, you want it also do something else, nut not on load, but when the program of form unload/quit?
thats why they have that, in the list of a form, you can select load, but also unload, you can add your own operations later when you are further in visual basic.

The operations are very usefull.
imagine, you want, when a textbox got focused ( selected ), that every letter you write, will be saved into an variable.
then, you can simply select textbox1 in the coding objectlist, and as operation, on keychange.
stringvar = textbox1.text
but, now it always does this, so, we put it in a timer, which can be disabled and enabled:

we now have, 1 textbox, and 1 timer, on form load do:
"timer1.enabled = false"
"timer1.interval = 250" without quotes

then to enable it,
select textbox1 in object menu, and operation gotfocus.
then type "Timer1.Enabled = true" without quotes
after done that, select lostfocus.
then type there
"Timer1.Enabled = False" without quotes

now the timer, is on focus enabled, and no focus disabled.
to make it work like we said, we need the timer do something
now,
to make a variable getting all text in textbox1, do the following:

dim variable as string
variable = texbox1.text

simple, yet effective.

now, we can test our program, because it does something.
you can do that, by clicking the blue "arrow" on the middle toolbar looking like this:


after everything is OK, we can make it an .EXE file, also known as Executeable
You can do that, by clicking FILE::>> Make "Project1".exe without quotes
note, if you renamed your project, the text between quites will be changed 2.


well, thats all for now, hope you learned something

fusion universe, sunreal
FuT , Fusion universe Tutorials
12  Tutorials / Programming and Scripting / Welcome on: July 29, 2008, 04:36:09 am
You guys are allowed to view and create tutorials about programming and scripting here.
Though there are some rules to this:

-No Virusses or infected files
-No Other Malware
-Do not include any kind of nudity, of sex,
-Post in the right section of the scripting or programming langauge
13  Artwork and projects / Backgrounds / energy overflow on: July 18, 2008, 01:16:49 pm


the author of this picture is my brother, roytjuh
14  Artwork and projects / Video's / Rules: when and what videos can i post? on: July 18, 2008, 12:52:03 pm
no ****, hentai, or racistm
15  Artwork and projects / Pictures / Rules: when and what pictures can i post? on: July 18, 2008, 12:51:10 pm
no ****/hentai pictures, racistm etc.
Pages: [1] 2
Bookmark this site! | Upgrade This Forum
Free SMF Hosting - Create your own Forum

Powered by SMF | SMF © 2016, Simple Machines
Privacy Policy