مشاهدة الموضوع الأصلي: Visual Basic
ديوان الثقافة » الدواوين التقنية » ديوان الكمبيوتر والإنترنت
CPU

بسم الله الرحمن الرحيم ،

لأي استفسار عن الفيجوال بيسك الرجاء الكتابة..

و السلام عليكم و رحمة الله و بركاته ..

wink.gif
Flash Master
السلام عليكم ورحمة الله وبركاته
  • هل يُمكن ربط الفلاش بالفيجوال بيسك؟

مثال : عمل فلاش يحوي زر ، وتضمينه بداخل برنامج الفيجوال بيسك وتنفيذ شفرة برمجية عند الضغط على الزر الفلاشي
CPU
و عليكم السلام و رحمة الله و بركاته،،

اقتباس
هل يُمكن ربط الفلاش بالفيجوال بيسك؟

نعم، يمكن تشغيل الفلاش من الVB و ذلك عن طريق الأوبجكت الخاصة
بالفلاش...

In the nanme of Allah,

You have to insert the Shockwave Flash Control into your project.
Just go to the Project's menu --> then choose components
--> then select Shockwave Flash
in the form load You can do the following:

[php]
Private Sub Form_Load()
ShockwaveFlash1.Movie = "c:\s.swf"
ShockwaveFlash1.Play
End Sub
[/php]
CPU

How can I run the Windows Mwdia Player in the VB ?

Just go to the Project's menu
then choose components
then select Windows Media Player
[php]
Private Sub Form_Load()
'Either we can set the FileName from the Properties
'Window, Or we can set it using the code
MediaPlayer1.FileName = "C:\WINDOWS\Media\ringin.wav"
End Sub
[/php]
CPU
How can I create an analog Clock ?
it needs some Math

[php]
Dim x, y, w, m

Private Sub Form_Paint()
' Geting the mid-point of the form to be (x,y)
y = Me.Height / 2
x = Me.Width / 2
w = 1700

'Drawing the Circle
DrawWidth = 4
Me.Circle (x, y), w
' Drawing the Hour Scorpion
DrawWidth = 4
Me.Line (x, y)-(x + (900 * Sin(Hour(Now) * 3.1415 / 6)), _
y - (900 * Cos(Hour(Now) * 3.1415 / 6))), &HFFFF00
' Drawing the Minute Scorpion
DrawWidth = 3
Me.Line (x, y)-(x + (1200 * Sin(Minute(Now) * 3.1415 / 30)), _
y - (1200 * Cos(Minute(Now) * 3.1415 / 30))), vbYellow
' Drawing the Second Scorpion
DrawWidth = 1
Me.Line (x, y)-(x + (1500 * Sin(Second(Now) * 3.1415 / 30)), _
y - (1500 * Cos(Second(Now) * 3.1415 / 30))), vbRed

End Sub

Private Sub Timer1_Timer()
Me.Cls
'Drawing the Circle
DrawWidth = 4
Me.Circle (x, y), w
' Drawing the Hour Scorpion
DrawWidth = 4
Me.Line (x, y)-(x + (900 * Sin(Hour(Now) * 3.1415 / 6)), _
y - (900 * Cos(Hour(Now) * 3.1415 / 6))), &HFFFF00
' Drawing the Minute Scorpion
DrawWidth = 3
Me.Line (x, y)-(x + (1200 * Sin(Minute(Now) * 3.1415 / 30)), _
y - (1200 * Cos(Minute(Now) * 3.1415 / 30))), vbYellow
' Drawing the Second Scorpion
DrawWidth = 1
Me.Line (x, y)-(x + (1500 * Sin(Second(Now) * 3.1415 / 30)), y - (1500 * Cos(Second(Now) * 3.1415 / 30))), vbRed
End Sub
[/php]

من هذا المثال نلاحظ أن سطر الكود إذا كان طويلا فيمكن تقسيمه إلى عدة أسطر
و ذلك باستخدام ال(Under Score)

مثال على ذلك:
[php]

Me.Line (x, y)-(x + (1500 * Sin(Second(Now) * 3.1415 / 30)), _
y - (1500 * Cos(Second(Now) * 3.1415 / 30))), vbRed[/php]
[attachmentid=73627 name=frmClock.frm]
CPU

Who to Run another App. using VB ?

We can use the Shell Command
Eg. we can run the ms calculator in one line like this:
[php]
Private Sub Command1_Click()
Shell "calc"
End Sub
[/php]

The Function Declaration
[php]Function Shell(PathName, [WindowStyle As VbAppWinStyle = vbMinimizedFocus]) As Double[/php]

From the above Declaration we can find that any expresion
that is between the Square Brackets is Optional>

What do we mean by "Optional" ?
Optional means that we can add that Parameter in the function Call.

For those people who have taken C++ courses,
they can think about it as Function Overloading
.
CPU

It seems that no one have at least one Question.
So I will ask ?

How can I get the System info like Windows Type, version using VB.. ?


You can simply include the component " Microsoft SysInfo Control 6.0 ".


[php]Private Sub Form_Load()

Select Case SysInfo.OSPlatform
Case 0
lstInfo.AddItem "OS Platform = Unknown 32-Bit Windows"
Case 1
lstInfo.AddItem "OS Platform = Windows 95"
Case 2
lstInfo.AddItem "OS Platform = Windows NT"
End Select

lstInfo.AddItem "OSVersion = " & SysInfo.OSVersion
lstInfo.AddItem "OSBuild = " & SysInfo.OSBuild
End Sub[/php]
[attachmentid=73784 name=OSInfo.zip]
CPU
HTML
I need MSDN ?


[php]First, excuse me to define it ..

What is the MSDN?
The MSDN is an abbreviation for Microsoft Developer Network,
it is used with Microsoft Studio and it provides the help about
the syntax of functions and many others..

* You can download It from Microsoft which will take some time that
you may not desire

* Or I can Copy it for you as well as for all our memebers
MSDN Comes in 2 CDs *

* Or, you can use the Online MSDN help through the following site
[/php]
http://msdn.microsoft.com
CPU
HTML
how can I :
1. write data to a sequential file?
2. read data from a sequentional file?

[php]
'just make 2 textboxes with a command button >>>

Option Explicit
Dim x As String
Dim y As String

Private Sub Command1_Click()
Open "C:/text.txt" For Input As #1
Line Input #1, x
Line Input #1, y
Close #1
Text1.Text = x
Text2.Text = y
End Sub

Private Sub Form_Load()
Open "C:/text.txt" For Output As #1
Print #1, "Here write the first line"
Print #1, "Here write the second line"
Close #1
End Sub[/php]
SQL
For any question please ask, ,,, .
CPU
HTML
How can I get the Difference between 2 dates ?


in order to get the difference between 2 days we use the function DateDiff ... see this :
[php]Dim TheDate As Date ' Declare variables.
Dim Msg
TheDate = InputBox("Enter a date")
Msg = DateDiff("d", Now, TheDate)
MsgBox Msg[/php]
CPU


and in order to get the difference between 2 months we use it like this:

[php]Dim TheDate As Date ' Declare variables.
Dim Msg
TheDate = InputBox("Enter a date")
Msg = DateDiff("m", Now, TheDate)
MsgBox Msg[/php]
CPU


and to get the difference between 2 years see this:

[php]Dim TheDate As Date ' Declare variables.
Dim Msg
TheDate = InputBox("Enter a date")
Msg = DateDiff("yyyy", Now, TheDate)
MsgBox Msg
[/php]
CPU
Start creating a new project and design the form as shown below.

user posted image


Write the VB code for the following command buttons:

DISPLAY CAPTION: This command button will display any caption
in "Label2". You can set your own caption within the code.
Eg. "Welcome To Visual Basic"

SEND TITLE TO TEXTBOX: This command button will send or rather
display the title of the form "UNIVERSITY OF BAHRAIN" to the text box
(NAME)

PICTURE ALIGNMENT: this will align the picture on the form to any direction
you desire.

MSGBOX: This will display a message box with a message.
For example: "Welcome to Visual Basic"


[attachmentid=74086 name=lab5.zip]
CPU

Design the form as shown below. The buttons that you see on the form are
basically used to alter different properties for the title and the shape that you see on the form.

user posted image


The functions of the buttons on the form are self-explanatory. Basically, you
have buttons that would alter properties for the title on the form, which is
"Visual Basic", and you also have buttons that would alter properties of the
shape on the form.

[attachmentid=74088 name=Lab6.zip]
CPU

Start creating a new project and design the form below. The purpose of this
project is to change the price for a computer by clicking on the ends of the
scrollbar.

user posted image

... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...

before you download the answer please go to the properties window
after selecting the horizontal scrollbar and notice Min and Max.

... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...

[attachmentid=74089 name=FrmPriceChanger.frm]
CPU

Design another form as shown below. The user has to enter some values in
the textboxes. Then, when the user clicks on the command button, the position of the picture will change with respect to the values entered.


user posted image

[attachmentid=74090 name=Lab7_2.zip]
ملاحظ
السلام عليكم،،

شكراً جزيلاً أخي CPU على هذه المعلومات الجميلة smile.gif

يبدو أنني سأقوم بتنصيب برنامج Visual Basic على جهازي لأجرّب معكم، وأتعلم rolleyes.gif

وإذا خطر ببالي أي استفسار، فلن أتوانى عن طرحه، وأنتم أهل للإجابة..

مع التحية،،
CPU

و عليكم السلام و رحمة الله و بركاته ،،،

اقتباس
شكراً جزيلاً أخي CPU على هذه المعلومات الجميلة
شكرا لك أخي wub.gif wub.gif
شكرا على التشجيع wub.gif
حياكم الله،
و لكن أرجو أن يكون شرحي مفيدا ..
اقتباس
وإذا خطر ببالي أي استفسار، فلن أتوانى عن طرحه، وأنتم أهل للإجابة..

حاضرين biggrin.gif .. في إطار معرفتي .. و الي ما أعرفه راح أكون سعيد في البحث عنه ..

wub.gif wub.gif

تحياتي CPU
CPU

:Design a project that contains the following form

user posted image
:Then write the VB code to accomplish the following
When you press on "Calculate Average", a message box should appear to
inform you that the average is being calculated then the result will be
displayed in the text box.


[attachmentid=75875 name=FrmCalcAvg.frm]
CPU
with the same form try to use variables....

such as:

dim var1 as integer
dim text1,text2 as single


[php]Private Sub CmdCalcAvg_Click()
Dim var1 As Single
Dim var2 As Single

MsgBox "The average is being calculated", vbInformation, "VB wait..."

var1 = Val(TxtTest1.Text)
var2 = Val(TxtTest2.Text)

TxtAvg = (var1 + var2) / 2

End Sub

Private Sub CmdClose_Click()
End
End Sub
[/php]
CPU
--> Creat a project that consists of the following form:

user posted image

The form should expect the user to enter employee's name, age,
nationality, company, and position.

"Next Employee" button should clear the form for the next employee
details.

"Employee Description" button should view all of employees details
in a message box.

"Exit" button should terminate the program.

Note:
. . . . . . . . All quantities should be assigned to variables

Example :

Ali Murad is an Advanced Programmer in VB Form. He is Bahraini and he is
21 years of age.

[attachmentid=75885 name=FrmEmployee.frm]
CPU

Start a new project, and design the following form. The project simulates a
cannon destroying countries. As you can see below, the boxes named x, y, z
are the countries.

user posted image

The objective of the project is, when the user selects one of the 'Country',
a bullet is fired, and a country is destroyed. A label ( in the position were the country was) indicates that a particular country has been destroyed. Also
a bullet appears were the country was hit. See below for an example.

user posted image

Further, the title on the form changes color every time a certain country
is selected. When all the countries have been destroyed, a message box should
appear with a message "All shapes destroyed. Game Over"

[attachmentid=75889 name=frmFireTheCountries.frm]
CPU

user posted image


[php]' Description: This project allows the receptionist to
'select discount rate and then select services. The
'Calculate button calculates amount due.

Private Sub cmdCalculate_Click()

' Calculate the total amount due after each
'service is entered
Const curMakeoverAmt As Currency = 125
Const curMakeupAmt As Currency = 200
Const curHairStylingAmt As Currency = 60
Const curManicureAmt As Currency = 35
Dim curService As Currency

'Calculate the price of the service
If optMakeover Then
curService = curMakeoverAmt
ElseIf optHairStyling Then
curService = curHairStylingAmt
ElseIf optManicure Then
curService = curManicureAmt
ElseIf optMakeup Then
curService = curMakeupAmt
Else
MsgBox "Select a Service. ", vbQuestion, "Missing Data"
End If

'Calculate the discount, if applicable
If optTen Then
curService = curService * 0.9
ElseIf optTwenty Then
curService = curService * 0.8
End If

lblAmountDue = FormatCurrency(curService)
End Sub

Private Sub cmdClear_Click()
'Clear the controls
optMakeover.Value = False
optHairStyling.Value = False
optManicure.Value = False
optMakeup = False
optTen.Value = False
optTwenty.Value = False
lblAmountDue.Caption = ""
End Sub

Private Sub cmdExit_Click()
'End the form
End
End Sub

Private Sub cmdPrint_Click()
'Print the form
PrintForm
End Sub
[/php]
CPU
[php]
Create a project that have the following properties:
-> The progarm should expect the user (the Health Club visitor)
to define himself first, and if not, nothing is active.

-> If defined, the user will be asked to enter his height and weight.

-> There must be a command button, that if clicked a factor called
BODY MASS INDEX (B.M.I) is calculated according to the following
equation: B.M.I = weight(Kg) / height(m)^2
[/php]

user posted image

[attachmentid=75893 name=FrmBMI.frm]
CPU

Open the falcon project and add a list box to enter video types and to
automatically compute the price.

user posted image

according to the following data:

..............................................
Video Type_______Video Price
_ Kids _________ 0.99
_ Regular _______ 1.99
_ Classic ________ 2.99
..............................................

[attachmentid=75898 name=Falcon_Video.zip]
الدمستاني
بااارك الله فيكم على هذا الابداع بالتوفيق لكم
CPU


السلام عليكم و رحمة الله
بارك الله فيكم و وفقكم wub.gif


تحياتي wub.gif
CPU
HTML
Create a program with the following user interface:


user posted image

[php]1) When the user clicks on the START button, an input box will appear
requesting user names to be added to the list. This will appear continuously
until the user is finished adding the names. A name that is already in the
list should not be added.

2) When the SEARCH button is clicked an Inout dialog will appear for the user
to enter the name to search for. The result should be displayed in a message
box.

3) When the Clear List button is clicked, all the names in the lists should be erased.

4) When the"List names starting with..." button is clicked the program
should check that there is only one character in the text box and list all the names
starting with that letter.
[/php]
[attachmentid=75966 name=frmSearch.frm]
CPU



and in order for you to be familiar with loops
I have included another answer to the above program

[attachmentid=75967 name=until_example.zip]
CPU
HTML
What are the Kinds of loops that we can use in VB6 ?

[php]In the name of Allah,

we have:

While (Condition)
'Statements
Wend
'==================================================
Do While (Condition)
'Statements
Loop
'==================================================
Do
'Statements
Loop While (Condition)

'==================================================
Do Until (Condition)
'Statements
Loop

'==================================================
Do
'Statements
Loop Until (Condition)

'==================================================
in addition to the For loop

For (Initial Value) To (Reached Value) Step (Increment Or decrement Value )
'Statements
Next (the loops Variable)
[/php]
CPU
HTML
He is example about loops:
You need to Open a new Form with 6 Clear textBoxes
and insert the following code in

[php]'==================================
' This code is to get the numbers form 0 to 5 in each of the textBoxes
'==================================
Private Sub Form_Load()
Dim i As Integer

While i <= 5
Text1 = Text1 & i
i = i + 1
Wend
'---------------------------------------------------
i = 0
Do While i <= 5
Text2 = Text2 & i
i = i + 1
Loop
'---------------------------------------------------
i = 0
Do
Text3 = Text3 & i
i = i + 1
Loop While i <= 5
'---------------------------------------------------
i = 0
Do Until i >= 6
Text4 = Text4 & i
i = i + 1
Loop
'---------------------------------------------------
i = 0
Do
Text5 = Text5 & i
i = i + 1
Loop Until i >= 6
'---------------------------------------------------
For i = 0 To 5 Step 1
Text6 = Text6 & i
Next i

End Sub
[/php]
CPU
HTML
What about the For loop..
How can I change it to generate the values from 5 to 0 ?

[php]We can get the decrement by Providing a negative Step Value.
And since you need 1 decrement so you should Provide the Step
with -1, as follows:

For i = 5 To 0 Step -1
Text6 = Text6 & i
Next i

Regards [/php]
CPU
HTML
Also we can use the goto like this

[php]Private Sub Command1_Click()
If Text1 = "123" Then
GoTo Correct
Else
GoTo Wrong
End If

Correct:
MsgBox "Correct", vbOKOnly, "Correct"
Text1 = ""
Exit Sub
Wrong:
MsgBox "Wrong", vbOKOnly + vbCritical, "Wrong"
Text1 = ""
End Sub
[/php]
[attachmentid=77497 name=frmGoto.frm]
CPU
HTML
How can I get the difference between 2 times

[php]Private Sub Form_Load()
Text2.Text = Format(Time, "HH:MM:SS")

H = Val(Mid(Text2.Text, 1, 2))
M = Val(Mid(Text2.Text, 4, 2))
S = Val(Mid(Text2.Text, 7, 2))
End Sub

Private Sub Timer1_Timer()
Text1.Text = Format(Time, "HH:MM:SS")

'this is the process of extracting H, M, and S
CH = Val(Mid(Text1.Text, 1, 2))
CM = Val(Mid(Text1.Text, 4, 2))
CS = Val(Mid(Text1.Text, 7, 2))

' getting the difference between Current and the Start Time

'getting the difference between the Seconds
If CS >= S Then
DifS = CS - S
Else
CS = CS + 60
DifS = CS - S
CM = CM - 1
End If

'getting the difference between the Minutes
If CM >= M Then
DifM = CM - M
Else
CM = CM + 60
DifM = CM - M
CH = CH - 1
End If

'getting the difference between the Hours
If CH >= H Then
DifH = CH - H
Else
CH = CH + 24
DifH = CH - H
End If

'Show the Difference
Text3.Text = Format(DifH, "00") & ":" & Format(DifM, 0) & ":" & Format(DifS, "00")

End Sub[/php]
CPU
[php]
' This is another answer
Private Sub Timer1_Timer()
Dim TimeIn As Date _
, TimeOut As Date _
, TimeDifferent As Date
'''''''''''''''''''''''''''''''
Dim HourDiff As Integer _
, MinuteDiff As Integer _
, SecondDiff As Integer
''''''''''''''''''''''''''''''
TimeIn = TimeValue(lblconnect.Caption)
''''''''''''''''''''''''''''''
TimeOut = TimeValue(lbltimenow.Caption)
''''''''''''''''''''''''''''''
TimeDifferent = (TimeOut - TimeIn)
HourDiff = Hour(TimeDifferent)
MinuteDiff = Minute(TimeDifferent)
SecondDiff = Second(TimeDifferent)

lblconnectiontime = HourDiff & " : " & MinuteDiff & " : " & SecondDiff

End Sub

Private Sub Timer2_Timer()
lbltimenow = Time
End Sub[/php]
CPU
HTML
How can i make a Cout Down Timer?

[php]Dim t As Date

Private Sub Form_Load()
t = "00:00:03" ' Period
Label1 = Format(t, "hh:mm:ss")
End Sub

Private Sub Timer1_Timer()
If (Format$(t, "hh:mm:ss")) <> "00:00:00" Then
t = DateAdd("s", -1, t) ' reducing 1 second
Label1 = Format$(t, "hh:mm:ss")
Else
MsgBox "Done"
Timer1.Enabled = False
End
End If
End Sub[/php]
CPU
بسم الله الرحمن الرحيم،
السلام عليكم و رحمة الله و بركاته،،

سؤال من أحد الزملاء الأعزاء:
كيف يمكن جعل البرنامج يظهر في شريط المهام ال(Task Bar) ،
كما يظهر المسنجر ؟


هذه المنطقة التي توجد بها الآيكونات في شريط المهام تسمى بالNotification Area
أو تسمى بال System Tray


System Tray
n. (in Windows operating systems) location on the taskbar in which the clock and other user-installed utilities reside, SYSTRAY
Babylon Dictionary


الدالة الوسيطية البرمجية (API (Application Program Interface
الوحيدة التي راح نستعملها هي :
Shell_NotifyIcon


و التعريف لها كالتالي:
Declare Function Shell_NotifyIcon Lib "shell32" Alias "Shell_NotifyIconA" _
(ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As Boolean
CPU
على كل ما راح أطول .. هذا هو الكود:
[php]' To create an Icon in System Tray

'declaration for putting the application to system tray
Private Type NOTIFYICONDATA
cbSize As Long
hwnd As Long
uId As Long
uFlags As Long
uCallBackMessage As Long
hIcon As Long
szTip As String * 64
End Type

'declare constants
Private Const NIM_ADD = &H0
Private Const NIM_MODIFY = &H1
Private Const NIM_DELETE = &H2

'The following constant is the message sent when a mouse event occurs
'within the rectangular boundaries of the icon in the taskbar status area.
Private Const WM_MOUSEMOVE = &H200

'The following constants are the flags that indicate the valid
'members of the NOTIFYICONDATA data type.
Private Const NIF_MESSAGE = &H1
Private Const NIF_ICON = &H2
Private Const NIF_TIP = &H4

'The following constants are used to determine the mouse input on the
'the icon in the taskbar status area.

'Left-click constants.
Private Const WM_LBUTTONDBLCLK = &H203 'Double-click
Private Const WM_LBUTTONDOWN = &H201 'Button down
Private Const WM_LBUTTONUP = &H202 'Button up

'Right-click constants.
Private Const WM_RBUTTONDBLCLK = &H206 'Double-click
Private Const WM_RBUTTONDOWN = &H204 'Button down
Private Const WM_RBUTTONUP = &H205 'Button up

'Declare the API function call.
Private Declare Function Shell_NotifyIcon Lib "shell32" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As Boolean

'Dimension a variable as the user-defined data type.
Dim nid As NOTIFYICONDATA

Private Sub C_Click()
Shell "Calc"
End Sub

Private Sub Form_Load()
Me.Hide
nid.cbSize = Len(nid)
nid.hwnd = Me.hwnd
nid.uId = vbNull
nid.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
nid.uCallBackMessage = WM_MOUSEMOVE
nid.hIcon = Me.Icon
'u can give a tool tip text here
nid.szTip = "My System Tray Message" & vbNullChar
'Call the Shell_NotifyIcon function to add the icon to the System Tray
Shell_NotifyIcon NIM_ADD, nid
MsgBox "In system tray"
End Sub

' Create a menu by using menu editor
'one main menu by Caption"Menu" name "M"
'one sub menu by name caption "Exit" name "Ex"
'make the Menu invisible by changing the "visibility" option in the Properties Window

' Write the following in MouseMove event
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim msg As Long
Dim sFilter As String
msg = X / Screen.TwipsPerPixelX
Select Case msg
Case WM_LBUTTONDOWN
' Me.PopupMenu M 'if u want u can call the popup menu
Case WM_LBUTTONUP
Case WM_LBUTTONDBLCLK
Case WM_RBUTTONDOWN
Case WM_RBUTTONUP
Me.PopupMenu M 'call the popup menu
Case WM_RBUTTONDBLCLK
End Select
End Sub

' Write the following in form_unload event
' Delete the icon when the form is unloaded
Private Sub Form_Unload(Cancel As Integer)
Shell_NotifyIcon NIM_DELETE, nid
End Sub

' Write the following for the sub menu
' Delete the icon when exit sub menu is selected
Private Sub Ex_Click()
Shell_NotifyIcon NIM_DELETE, nid
End
End Sub
[/php]
[attachmentid=78183 name=frmSysIcon.FRM]
لبنة
السلام عليكم ورحمة الله وبركاته
معلومات جميلة اشكرك عزيزي CPU والله يوفقك كثيرا
يصلح الموضوع ان يكون مرجع مفيد لما نريد نتعلم Visual Basic smile.gif
CPU

شكرا جزيلا على التشجيع wub.gif wub.gif
CPU
HTML
How can I get the Asci Code of the KeyBoad Keys ?

[php]Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
lblKeyCode = ""
lblChrKey = ""

lblKeyCode = KeyCode
lblChrKey = Chr(KeyCode)
End Sub
[/php]
[attachmentid=86566 name=frmKeyCode.frm]
CPU
HTML
How can I execute SQL Commands from the VB ?

[php]Private Sub Command1_Click()
On Error GoTo errDesc
Label1 = ""
Dim conn As ADODB.Connection
Set conn = New ADODB.Connection
conn.ConnectionString = _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=db1.mdb;"

conn.Open
conn.Execute Text1
conn.Close
Exit Sub

errDesc:
Label1 = Err.Description
End Sub
[/php]
[attachmentid=86568 name=SQL_Command.zip]
CPU
HTML
How can I convert the text that is written in a textBox from
the lowercase into the uppercase?

[php]
Private Sub Text1_Change()
Text1 = UCase(Text1)
Text1.SelStart = Len(Text1)
Text1.SetFocus
End Sub
[/php]
ملاحظ
السلام عليكم،،

الأخ الفاضل CPU شكراً جزيلاً لجهودك الكريمة smile.gif

لقد استفدت كثيراً، وسأستفيد من الموضوع بكل تأكيد مستقبلاً smile.gif smile.gif

مع التحية،،
CPU

السلام عليكم و رحمة الله و بركاته،،

اقتباس
الأخ الفاضل CPU شكراً جزيلاً لجهودك الكريمة
شكرا جزيلا لكم عزيزي،،
و شكرا لاستضافتي في الديوان biggrin.gif

اقتباس
لقد استفدت كثيراً، وسأستفيد من الموضوع بكل تأكيد مستقبلاً
الحمد لله،، هذا ما أرجوه.
CPU
HTML
How can I create a Command Button During Program Run Time ?

[php]Option Explicit

Private WithEvents new_button As CommandButton

Private Sub Command1_Click()
Command1.Enabled = False
' Creating the new Button
' this string "VB.CommandButton" means that the CommandButton
' is a member of the Class VB, and using the method Add we can
' add a new button
Set new_button = Me.Controls.Add("VB.CommandButton", "cmdNew")
' Setting the Position of the button
With new_button
.Move Command1.Left, Command1.Top + Command1.Height + 120
.Caption = "New Button"
.Visible = True
End With
End Sub

' The is the Click Event or the newly allocated buttom
Private Sub new_button_Click()
MsgBox "Clicked"
End Sub
[/php]
[attachmentid=90189 name=frmDynamicallyCreation.frm]
CPU
HTML
Another way of creating a Button through Dynamically Memory Allocation

[php]
' here we are using the load keyword in order to load a new object
' in the memory
Private Sub Command1_Click(Index As Integer)
If Index = 0 Then
Load Command1(1)
Command1(1).Left = Command1(0).Left
Command1(1).Top = Command1(0).Top + Command1(0).Height + 120
Command1(1).Visible = True

Command1(0).Enabled = False
ElseIf Index = 1 Then
'Setting the event for the newly allocated CommandButton
MsgBox " Clicked "
End If
End Sub
[/php]
CPU
HTML
The same way we can Load a Command Button- > we can Unload it

[php]Unload Command1(1)[/php]

و هذا هو المثال كامل

[php]Private Sub Command1_Click(Index As Integer)
If Index = 0 Then
Load Command1(1)
Command1(1).Left = Command1(0).Left
Command1(1).Top = Command1(0).Top + Command1(0).Height + 120
Command1(1).Visible = True

Command1(0).Enabled = False
ElseIf Index = 1 Then
'Setting the event for the newly allocated CommandButton
MsgBox " Clicked "
End If
End Sub

Private Sub Command2_Click()
On Error GoTo ErrDesc
Unload Command1(1)
Command1(0).Enabled = True
Exit Sub
ErrDesc:
MsgBox Err.Description
End Sub
[/php]
[attachmentid=92198 name=frmLoadCommandButton.frm]
CPU
HTML
The same way we can load a Command Button we can load any Other Object

[php]Private Sub Command1_Click()
Load List1(1)
Command1.Enabled = False
List1(1).Left = List1(0).Left + 1500
List1(1).Visible = True
End Sub
[/php]

Notice:
When using the KeyWord Load to load an object we
need to have a control array of that Object
[attachmentid=92199 name=frmLoadList.frm]
CPU
HTML
How can I check whether a file exists or not?

[php]We Can try to open it -> if it is opened then it exists,
else it does not exist
--------------------------------------------------------------------------------------------

Function Validate_File(ByVal FileName As String) As Boolean
Dim fileFile As Integer
'Attempt to open file
fileFile = FreeFile
On Error Resume Next
Open FileName For Input As fileFile

'Ccheck for error
If Err Then
Validate_File = False
Else
'File exists
'Close file
Close fileFile
Validate_File = True
End If
End Function

Private Sub Command1_Click()
If Validate_File("c:\boot.ini") Then
MsgBox "File Exists"
Else
MsgBox "File does not exist"
End If
End Sub
[/php]
CPU
HTML
Another way to verify a file is using "Dir" like this:

[php]Private Sub VerifyFile(ByVal myFilePath)
Dim found As String
found = Dir(myFilePath)

If found = "" Then
MsgBox "Does not Exist"
Else
MsgBox "Exists"
End If
End Sub

Private Sub cmdVerifyFile_Click()
Call VerifyFile("C:\Windows\0.log")
End Sub
[/php]
CPU
HTML
How can I retrieve the data from an Access dataBase?

أولا لازم نفتح بروجكت جديد و انضيف ال Component التالية:
Microsoft ADO Data Control 6.0

و اللتي يمكن إضافتها بالذهاب إلى ال Project Menu أو بالضغط على Ctrl+T
و من ثم اختيار Components..
ثم Microsoft ADO Data Control 6.0

راح تنضاف هذه الأداة إلى ال ToolBox و من ثم يمكننا ادراجها على الفورمة و استخدامها

user posted image

ثم نأتي لوضع ال Connection String اليي راح نضبط فيه ال Provider و ال Data Source
و الPassword إذا كانت الديتابيس محمية بكلمة مرور. و يتم ذلك بالضغط على أداة ال ADO بالزر الأيمن
و من ثم اختيار Propoerties

user posted image

و من ثم نضغط على Build

user posted image

و من ثم في قسم ال Provider نختار Microsoft Jet 4.0 OLE BD Provider

user posted image

و من ثم نضغط على Next أو نذهب إلى القسم: Connection
و من ثم نختار مكان وجود الديتابيس - ال Path.

user posted image

و بعد ذلك نضغط على
Test Connection لنتأكد من صحة ارتباط ال ADO بالديتابيس.

user posted image

ثم OK و بعدها OK
و نأتي الآن لتحديد ال RecordSource

user posted image


في نقطة مهمة جدا:
كل ADO لابد أن يكون هناك Control أخرى مثل TextBox أو Label
ال DataSource مالها هو هذه ال ADO

فمثلا نأتي للليبل lblID و نحدد ال DataSource Property في ال Properties Window
بحيث تكون adoEmployees كما بالصورة:

user posted image

خلوننا ألحين أنحدد ال DataField لكل من الليبلين lblID و lblName حتى يكونان مربوطين بالFields
اليي بالديتابيس.

user posted imageuser posted image

و هذا يعني أن ال Fields بالديتابيس هما ID و Name

و الآن دعونا نكتب الكود(الشفرة) للالزرار:
[php]Private Sub cmdFirst_Click()
adoEmployees.Recordset.MoveFirst
End Sub

Private Sub cmdLast_Click()
adoEmployees.Recordset.MoveLast
End Sub

Private Sub cmdNext_Click()
If Not adoEmployees.Recordset.EOF Then
adoEmployees.Recordset.MoveNext
End If
End Sub

Private Sub cmdPrevious_Click()
If Not adoEmployees.Recordset.BOF Then
adoEmployees.Recordset.MovePrevious
End If
End Sub
[/php]



[attachmentid=134690 name=Employees.zip]
حفصة
السلام عليكم،

شكراً أخي Central Process Unit

بحاول أتابع دروسكم إن شاء الله.

بس عاد إذا صار عندي وقت، لأن في مسابقات وايد.


تحياتي:
حفصة tongue.gif
CPU
اقتباس (حفصة @ 9-01-2006, 06:31 صباحاً)
بحاول أتابع دروسكم إن شاء الله.


و عليكم السلام و رحمة الله

عفوا wub.gif . هذا من دواعي سروري
و أهم شيء الأسئلة biggrin.gif
اليي عنده سؤال يسأل و حتى لو ما نعرف نتعلم tongue.gif
CPU
أحد الزملاء يسأل:

HTML
How can we retrieve the database data into a listBox?
[php]Private Sub cmdFill_Click()
Do Until adoEmployees.Recordset.EOF

lstEmployees.AddItem adoEmployees.Recordset!ID & vbTab & _
adoEmployees.Recordset!Name

adoEmployees.Recordset.MoveNext
Loop
End Sub[/php]

user posted image

[attachmentid=134718 name=Employees1.zip]
لمشاهدة الديوان بالشكل الأصلي، انتقل لـ Visual Basic - ديوان الثقافة