Search VB 2010

Friday, November 25, 2011

Visual Basic 2010 Math Functions

Microsoft Visual Basic 2010

Math Functions
Visual Basic 2010 Math functions
Visual Basic 2010 Math functions
Math and String Functions
In addition to performing simple arithmetic and string operations with the arithmetic and string operators, Visual Basic programs can take advantage of several built-in mathematical functions and string functions to perform useful processing that, otherwise, could require highly complex original code.
Mathematical Functions
Popular mathematical functions are summarized in the following table. Note that certain functions do not require the Math. prefix.
Math.Abs()Returns the absolute value.
Math.Abs(-10) returns 10.
Math.Ceiling()Returns an integer that is greater than or equal to a number.
Math.Ceiling(5.333) returns 6.
Fix()Returns the integer portion of a number.
Fix(5.3333) returns 5.
Math.Floor()Returns an integer that is less than or equal to a number.
Fix(5.3333) returns 5.
Int()Returns the integer portion of a number.
Int(5.3333) returns 5.
Math.Max()Returns the larger of two numbers.
Math.Max(5,7) returns 7.
Math.Min()Returns the smaller of two numbers.
Math.Min(5,7) returns 5.
Math.Pow()Returns a number raised to a power.
Math.Pow(12,2) returns 144.
Rnd()Returns a random number between 0 and 1. Used in conjunction with Randomizestatement to initialize the random number generator.
Math.Round()Rounds a number to a specified number of decimal places. Rounds up on .5.
Math.Round(1.1234567,5) returns 1.12346.
Math.Sign()Returns the sign of a number. Returns -1 if negative and 1 if positive.
Math.Sign(-5) returns -1.
Math.Sqrt()Returns the square root of a positive number.
Math.Sqrt(144) returns 12.
Random Numbers
The Rnd() function returns a random number between 0 and 1. More likely, the need is to generate a number within a particular range, between a given low and high number. This is accomplished with the following formula.
Math.floor((high - low + 1) * Rnd() + low)
For instance, to generate a random number between 0 and 10 the formula becomes
Math.floor((10 - 0 + 1) * Rnd() + 0)
String Functions
Several built-in string functions perform string manipulations to augment simple concatenation with the "&" operator. These functions are summarized in the following table.
Asc()Returns the character code of the first character of a string.
Asc("A") returns 65.
Chr()Returns the display character of a character code.
Chr(65) returns "A".
GetChar()Returns the character at a specified position in a string, counting from 1.
GetChar("This is a string", 7) returns "s".
InStr()Returns the starting position in a string of a substring, counting from 1.
InStr("This is a string", "string") returns 11.
InStrRev()Returns the starting position in a string of a substring, searching from the end of the string.
InStr("This is a string", "string") returns 11.
LCase()Returns the lower-case conversion of a string.
LCase("THIS IS A STRING") returns "this is a string".
Left()Returns the left-most specified number of characters of a string.
Left("This is a string", 4) returns "This".
Len()Returns the length of a string.
Len("This is a string") returns 16.
LTrim()Removes any leading spaces from a string.
LTrim("   This is a string") returns "This is a string".
Mid()Returns a substring from a string, specified as the starting position (counting from 1) and the number of characters.
Mid("This is a string", 6, 4) returns "is a".
Replace()Replaces all occurrences of a sub-string in a string.
Replace("This is a string", " s", " longer s") returns "This are a longer string" (replaces an "s" preceded by a blank space).
Right()Returns the right-most specified number of characters of a string.
Right("This is a string", 6) returns "string".
RTrim()Removes any trailing spaces from a string.
RTrim("This is a string   ") returns "This is a string".
Str()Returns the string equivalent of a number.
Str(100) returns "100".
Space()Fills a string with a given number of spaces.
"This" & Space(5) & "string" returns "This     string".
StrComp()Compares two strings. Return values are 0 (strings are equal), 1 (first string has the greater value), or -1 (second string has the greater value) based on sorting sequence.
StrComp("This is a string", "This string") returns -1.
StrReverse()Reverses the characters in a string.
StrReverse("This is a string") returns "gnirts a si sihT".
Trim()Removes any leading and trailing spaces from a string.
Trim("   This is a string   ") returns "This is a string".
UCase()Returns the upper-case conversion of a string.
UCase("This is a string") returns "THIS IS A STRING".
Val()Converts a numeric expression to a number.
Val( (1 + 2 + 3)^2 ) returns 36.
The above summaries give you a basic idea of the uses of these arithmetic and string functions. There are occasions throughout these tutorials to see them in action and in combination as they are applied to various processing needs.

VB.Net SqlServer DateTime Insertion

Dealing with Date/Time in VB.Net and SQLServer

It's been a nightmare since i decided to insert DateTime value into Sql Server 2000 DataBase Table Field Type as SmallDateTime.It took me 3 days and nights trying to work it around.I've did everything i know and everything other told me to do.Finally, i figured it out.
Look ....
Say, you have a Vb.Net 2005 Project with a form contains a DateTimePicker Control called (Q3) and Button Called (B3) Text Property as (Insert), and you have Sql Server 2000 DataBase called (Market) with Table Called (Purchase) includes a Field called (EXdt) Type as (SmallDateTime) Length (4), and you want to update it using Ado.Net Online Mode.
1) Calling The Ado.Net for Sql Server DataBase
Imports System.Data.SqlClient
2) Assigning your variables
Dim CN As New SqlClient.SqlConnection
Dim cPur As New SqlClient.SqlCommand
Dim CntRs As Integer
Dim SqlStr As String
3) Connecting your DataBase 'Market' - Form_Load Event

If CN.State = ConnectionState.Open Then CN.Close()
        CN.ConnectionString = "Data Source=Your_Sql_Server_Name;Initial Catalog=Market;Integrated Security=True"
4) Connecting your table 'Purchase' - Form_Load Event

SqlStr = "Select * from Purchase"
        With cPur
            .Connection = CN
            .CommandType = CommandType.Text
            .CommandText = SqlStr
        End With
5) Inserting the date within the DateTimePicker Control (Q3) Into Field (EXdt)
SqlStr = "Insert Into Purchase (ExDT) Values ('" & Q3.Value.ToString("yyyy/MM/dd") & "')"
cPur.CommandText = SqlStr

CntRs = cPur.ExecuteNonQuery()
        MsgBox("( " & CntRs & " ) Record(s) Saved")
Congratulations ....
Download The Source Code Via MediaFire Link

If you have any other problem contact me by Comments - or -
you can simply Google me for more solutions (evry1falls - Your Problem)

Saturday, November 19, 2011

Visual Basic Online Courses DataGridView Add Edit Delete

Manipulate DataGridView from Visual Basic 2010 with SQL Server

DataGridView Add, Edit, Delete From Database
Visual Basic Online Course - DataGridView SQL Server Database
Note : if you dunno how to work SqlServer With VB.Net : You need to see this then this
  •  Logic
Using DataGridView Control In VB.Net to Add New - Edit - Delete from/to Sql Server Database or MS-Access or any other Database type. You will find in the end of the lessons the project to download along with source code .
  • Design :
1) Create a new Visual Basic project (Windows Application) name it as (MyDg1) and save it to your hard drive.
2) Place a DataGridView Control on the Form1.
3) Create Sql Server Database file, name it (MyDB)
4) Create Table, name it (Kinds) with just one record, name it (Kinds)
5) Rename the DataGridView Control's name From (DataGridView1) to (DG1)
6) Save/Build the project .
7) Now you have : A project such as this one in the 3 photos (from inside VB.Net and from Outside)
Visual Basic Online Courses
DataGridView Project From Inside VB.Net 2005
Visual Basic Courses Online
DataBase (MyDB) & Table (Kinds) From Inside SqlServer
Courses of Visual Basic online
Project Folder on DeskTop With DataBase Inside
- What do we want to do ?!!!!
we want to update the database (MyDB) Table (Kinds) Record (Kind) using DataGridView (DG1) From MS Visual Basic .Net 2005 on WinXpSp2 Home Edition ........ ahahahaha ok?!!

We will use NO buttons, we will only use DG1 Events :
1) For Adding New Record : you type in the cell in the dg1 and hit Enter Key
2) For Editing : you Edit a cell that already have been saved and hit enter
3) For Deleting : you Select a cell in the DG1 and you hit Delete key in the keyboard .
* Of course you can not add Empty Values because we have the record (Kind) is Primary Key (PK) .
* You can not Delete the (New DG1 Row) ...
All you have to do now is to open the Form1 Code and Clear all lines using (Ctrl+A) and (BackSpace) then Save Project (Ctrl+S) then Paste (Ctrl+V) these blocks of Codes :

Codes above works 100% just create the database and the table and the record successfully,

Friday, November 04, 2011

Visual Basic Online Course - SQL Server

قمنا بربط الـ Visual Basic .Net مع قاعدة بيانات من نوع MS Sql Server 2000 و قمنا بعمل مشروع Project باسم (SqlServer2000) عبارة عن Form تحتوى على Name - BirthDate - Age
و الان سنقوم ببرمجة المفاتيح الموجوده على Form و هى (New - Save - Edit - Delete - Search - Exit) و هى تعتبر مفاتيح رئيسية فى جميع المشروعات و يبقى المفتاح (Print) و سنقوم (ان شاء الله) ببرمجته فى موضوع لاحق لانه مرتبط بالتقارير Crystal Reports .
أولا : المفتاح New

و وظيفته تفريغ الخانات الموجوده على الـ Form لتهيئتها لاستقبال قيم جديده .
Code :
الاجراء ClearAll

ثم فى الحدث Click للمفتاح New نضع اسم الاجراء

الحدث Click للاداه Button1 مفتاح New

قم بتجربة المفتاح و املأ الادوات على الـ Form و لاحظ ..

ثانيا : المفتاح Save
و وظيفته حفظ القيم المدخلة فى الادوات فى جدول Basic قاعدة البيانات Info
Code : 

الحدث Click للاداه Buuton2 مفتاح الحفظ
قم بكتابة البيانات على الفورم فى جميع الخانات و اضغط على حفظ و لاحظ .

ايضا سنقوم بعمل معادلة لحساب السن تلقائيا بمجرد تغيير تاريخ الميلاد كالتالى .
الحدث ValueChanged للاداه DateTimePicker1 لحساب العمر تلقائيا

قم بتكرار حفظ جديد و لاحظ عند تسجيل تاريخ الميلاد يظهر السن تلقائيا و اضغط على Save و لاحظ ...
عند فتح جدول قاعدة البيانات سيكون لديك عدد (2) سجل ... أى ان التسجيل تم بنجاح . 
ثالثا : المفتاح Search
و سيكون البحث بدلالة الاسم Name
Code :

الحدث Click للاداه Button5 مفتاح البحث بدلالة الاسم

وسنقوم بالضغط على مفتاح Search ونكتب اى اسم تم حفظة و لاحظ ان البيانات تظهر على الـ Form .

رابعا : المفتاح Edit
حيث سنقوم بالبحث أولا ثم التعديل .
Code :

مفتاح التعديل Edit

نبحث عن اى سجل تم تعديلة للتأكد من التعديل .

خامسا : المفتاح Delete
بالمثل كما حدث فى التعديل سنقوم بالبحث أولا ثم الحذف .
Code :
مفتاح الحذف Delete
بعد الحذف نبحث عن سجل محذوف للتأكد من حذفه .

سادسا : المفتاح Exit
للخروج من البرنامج .
Code :

مفتاح انهاء البرنامج Exit

و السطر الاول معناه الخروج من قاعدة البيانات حتى لاتظل مفتوحة بعد الخروج من البرنامج ..

أرجو أن يكون الموضوع نال اعجابكم
أى سؤال فى التعليقات ان شاء الله .
Google Me to find Similar Useful Pages ( Evry1falls)

Here are some online Visual Basic lessons and courses :

Visual Basic Courses - Share