what is module and class module. I want to learn about it . anybody help me clearly.

Recommended Answers

All 20 Replies

For more information, just do googling more hard than me. :)

thanks. I have a idea about moudle and class moudle. now i try a project with it. so please help me.
I have 9 text box. they will change with 2 color red and blue when i click each text box. when i click a button they will become white. it is easy if i write a code in the command button. but i need, they will become white when all text box will fill with red and blue. i write a long code every text box like text1.backcolor = vbwhite.
now i write it with a moudle. how it possible. please help

i didn't understand clearly what you want.
>> they will change with 2 color red and blue when i click each text box. when i click a button they will become white
You mean randomize 2 color if we click textbox (we don't know what color will came up, it can be red or blue). Right?

>> but i need, they will become white when all text box will fill with red and blue
you mean :
if all textbox.backcolor <> vbwhite then
change all textbox.color = vbwhite.
Right ?

If u have done to write code in form, i think its easy to write it into module.
just make it as procedure or function and you can call it as u needed.
So, Post your code.... :)

I send my project. If you see other problem please help me. I want to learn more.

I already see your project.
You write too many if statement (make me dizzy) and it redundant.
Actually you can simplify your if statement become a function. so you just call function in each textbox checking.
I modified your program with added a module. In this module i put a function to check who is won and function to make all backcolor of textbox is white.

Module using to declare function/procedure or variable. with module you can call each function or variable from any form.

NB : you can make this program more simplify again. just see redundant if statement and exchange it become a function/procedure.

commented: you make this program so simply.... +1

few question :
Call CheckWinner(Text1, Text2, Text3)
here text1 mean t1 what was write in the module?

please explain under few lines. what is controlx?
Public Sub SetBackColor()
For Each controlx In Form1.Controls
If TypeOf controlx Is TextBox Then
controlx.BackColor = vbWhite
Next controlx
End Sub

>> Call CheckWinner(Text1, Text2, Text3)
here text1 mean t1 what was write in the module?
Yes. text1 will assigned with T1, then T1 used to check back color of textbox.

>> Public Sub SetBackColor()
For Each controlx In Form1.Controls
If TypeOf controlx Is TextBox Then
controlx.BackColor = vbWhite
Next controlx
End Sub.
please explain under few lines. what is controlx?

Controlx is a Control (Form1.controls). It can be any controls (textbox, button,label, etc).
But in this function i check controlx as textbox.
See this line : If TypeOf controlx Is TextBox so i check on the form1, if i find text box control in form1 then back color of textbox become white. So you didn't have to spending times for writing code to change all textbox back color one by one, but you can do it with check control type. If control type is textbox then u can change any properties of text box (backcolor in this case).

You can change controlx type (ex. button) :

For Each controlx In Form1.Controls
If TypeOf controlx Is CommandButton Then
controlx.BackColor = vbWhite
Next controlx
End Sub

this code means for every controlx, if controlx is button then back color of button become white.

commented: You work to hard for this :) +1

Public Function CheckWinner(T1 As TextBox, T2 As TextBox, T3 As TextBox)
If (T1.BackColor = vbBlue) And (T2.BackColor = vbBlue) And (T3.BackColor = vbBlue) Then
MsgBox "" & jewel & " win", vbOKOnly, "win"
SetBackColor
End If
End Function

here the veriable jewel didn't work. what i need to do for it.

why it didn't work?what error come up?
and it not variable but function. and it working for me when i post an attachment.

in general declaration i declare it.
Dim sohel, jewel As String

ya you right. but when i input name of a new player, it save in the option button. but when the game finish the msg show "win" . not show the name. I mean "abu taher win".

oh...i'm sorry for that (missing it).
In general declaration, you declare sohel and jewel but one by one.

Dim sohel As String
Dim jewel As String

then in module, add parameter of CheckWinner()

Public Function CheckWinner(T1 As TextBox, T2 As TextBox, T3 As TextBox, sohel As String, jewel As String)
If (T1.BackColor = vbBlue) And (T2.BackColor = vbBlue) And (T3.BackColor = vbBlue) Then
    MsgBox "" & jewel & "  win", vbOKOnly, "win"
    SetBackColor
End If
If (T1.BackColor = vbRed) And (T2.BackColor = vbRed) And (T3.BackColor = vbRed) Then
    MsgBox "" & sohel & "  win", vbOKOnly, "win"
    SetBackColor
End If
End Function

So, when u call it at form you must to add 2 parameter again :
ex :

....
Call CheckWinner(Text1, Text2, Text3, sohel, jewel)
....

do it to all CheckWinner calling function.

if you donn't mind i have few question.
1)
Dim sohel As String
Dim jewel As String

It is for input name in the option button?
2)
Public Function CheckWinner(T1 As TextBox, T2 As TextBox, T3 As TextBox, sohel As String, jewel As String)

here sohel as string for msgbox?
3) is there any connection between no. 1 and no. 2 question? i mean if write in checkwinner fox as string then it will work?

1. Yes, its for input name.
2. Yes, sohel used to know input name and show in msgbox. (same for jewel)
3. Yes, it connected.
First, sohel in CheckWinner function parameter and sohel in global declaration is different.
Sohel in checkwinner paramete got player name from sohel in global variable (from inputbox).
So you can change sohel paramete in checkwinner function with other name variable, its just a variable name. Same too for jewel.
Ex : sohel is fox and jewel is xof

Public Function CheckWinner(T1 As TextBox, T2 As TextBox, T3 As TextBox, fox As String, xof As String)
If (T1.BackColor = vbBlue) And (T2.BackColor = vbBlue) And (T3.BackColor = vbBlue) Then
    MsgBox "" & xof & "  win", vbOKOnly, "win"
    SetBackColor
End If
If (T1.BackColor = vbRed) And (T2.BackColor = vbRed) And (T3.BackColor = vbRed) Then
    MsgBox "" & fox & "  win", vbOKOnly, "win"
    SetBackColor
End If
End Function

But its still same when u call CheckWinner function (i mean the way to call).
Ex :

...
....
Call CheckWinner(Text1, Text2, Text3, sohel, jewel) ' sohel & jewel from global var
....
...

here, sohel and jewel from global variable for input name in the option button.

commented: thanks. I realy get a lot of help. +1

If I have other variable with (dim sohel as string) like dim ab as integer then the variable fox will work?

just
dim sohel as string
dim jewel as string
dim ab as interger

then the fox variable will work with msg?

>> If I have other variable with (dim sohel as string) like dim ab as integer then the variable fox will work?
i didn't get what u mean.

what a function of variable ab?

>> Sohel in checkwinner parameter got player name from sohel in global variable (from input box).

here your line mean a connection. I mean if I declare any other variable in general declaration (or other procedure) with my other variable (dim sohel as string) like dim ab as string or dim ab as integer, then Sohel in checkwinner paramete got player name from sohel in global variable (from inputbox)?
if your answer yes then please explain why Sohel in checkwinner parameter got player name from sohel in global variable (from input box)? why not got player name or other from other variable what I declare other variable.

Ok. i understand it.
you mean why sohel in checkwinner got player name from sohel in global variable and why didn't get from other variable.

sohel in checkwinner get value when you called checkwinner and put which variable to used.
Ex :
there are 3 variable in global declaration

Dim ab as string
Dim sohel as string
Dim jewel as string

...
when u call checkwinner function you must fill parameter value.
say you want using ab as input value. then it become bellow code : Call CheckWinner(Text1, Text2, Text3, ab, jewel) so, ab will giving value and checkwinner get value from ab not sohel again.

Thanks a lot for details help.

You're Welcome :)

commented: yes +2
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.