Fungsi-Fungsi Dalam Visual Basic 6.0

Pada tugas kali ini, saya akan menjelasakan tentang Fungsi ( Function ) yang berada pada Visual Basic 6.0. Dengan menggunakan functions bawaan Visual Basic 6.0 Anda bisa menggunakan perintah coding lebih pendek dan tidak memusingkan. Jadi functions dalam Visual Basic 6.0 sangat bisa meperkecil ukuran file dari sebuah program. Selamat belajar.
 
Function IIF
 
Rumus:
IIF (Expression, TruePart, FalsePart)
Fungsi IIF berguna untuk membandingkan 2 ekspresi yang berbeda. Sebagai contoh. Saya membuat 1 TextBox (txtIif) dan 1 CommandButton (cmdIif), seperti gambar di bawah :
Lalu memberi coding pada cmdIif :
Private Sub cmdIif_Click()
MsgBox IIf(txtIif.Text >= 81, “Nilai A”, “Tidak Nilai A”), vbOKOnly, “Iif” End Sub
 
Saat program dijalankan, lalu Anda memasukkan nomor di txtiIf, lalu menekan tombol cmdiIf, maka muncul MessageBox :
 
Function InputBox
 
Rumus:
InputBox(Prompt, [Title], [Default], [XPos], [YPos], [HelpFile], [Context]) As String
Fungsi InputBox berguna untuk menampilkan kotak Input. Sebagai contoh.
Saya membuat 1 CommandButton (cmdInputBox), seperti gambar di bawah :
Lalu memberi coding pada cmdInputBox :
Private Sub cmdInputBox_Click()
InputBox “Masukkan Kata atau Kalimat”, “Input Box”,
“Masukkan Kata Disini….”, 1212, 777 End Sub
Saat program dijalankan, lalu menekan tombol cmdInputBox maka muncul kotak Input Box :
Anda bisa melihat sendiri apa maksud dari coding:
  • Masukkan Kata atau Kalimat = memberikan pernyataan pada form
  • Input Box = memberikan judul di TitleBar
  • Masukkan Kata Disini… = memberikan pernyataan pada TextBox  1222 & 777 = menempatkan InputBox di koordinat yang diinginkan

Function InStr
 
Rumus:
InStr([Start], [String1], [String2], [Compare As VbCompareMethod = vbBinaryCompare])
Fungsi InStr berguna untuk mengetahui string pada sebuah variabel berada pada posisi ke-X. Sebagai contoh. Saya membuat 1 CommandButton (cmdInStr), seperti gambar di bawah :
Lalu memberi coding pada cmdInStr :
Private Sub cmdInStr_Click()
MsgBox InStr(“Imam Ciptarjo”, “Ciptarjo”), vbOKOnly, “InStr”
MsgBox InStr(“Imam Ciptarjo”, “a”), vbOKOnly, “InStr”
MsgBox InStr(5, “Imam Ciptarjo”, “a”), vbOKOnly, “InStr” End Sub
Saat program dijalankan, lalu Anda menekan tombol cmdInStr, maka muncul MessageBox :
Penjelasan :
MessageBox 1 = MsgBox InStr(“Imam Ciptarjo”, “Ciptarjo”), vbOKOnly, “InStr”
Menghasilkan nilai=6 karena Ciptarjo pada Imam Ciptarjo, terdapat pada posisi ke 6.
MessageBox 2 = MsgBox InStr(“Imam Ciptarjo”, “a”), vbOKOnly, “InStr” Menghasilkan nilai=3 karena a pada Imam Ciptarjo, terdapat pada posisi ke 3.
MessageBox 3 = MsgBox InStr(5, “Imam Ciptarjo”, “a”), vbOKOnly, “InStr” Menghasilkan nilai=10 karena a pada Imam Ciptarjo, terdapat pada posisi ke 10, tetapi dimulai dari posisi 5. Jadi a pada posisi 3 diabaikan.
 
 
Function Int
 
Rumus: Int(Number)
Fungsi Int berguna untuk mengetahui isi dari objek atau variabel ini number atau bukan number. Sebagai contoh. Saya membuat 1 CommandButton (cmdInt), seperti gambar di bawah :
Lalu memberi coding pada cmdInt : Private Sub cmdInt_Click()
If Int(999) Then
MsgBox “Number”, vbOKOnly, “Int”
Else
MsgBox “Bukan Number”, vbOKOnly, “Int”
End If
End Sub
Saat program dijalankan, lalu Anda menekan tombol cmdInt, maka muncul MessageBox :
 
Function IsArray
 
Rumus:
IsArray(VarName) As Boolean
Fungsi IsArray berguna untuk mengetahui isi dari objek atau variabel Array atau bukan Array. Sebagai contoh. Saya membuat 1 CommandButton (cmdIsArray), seperti gambar di bawah :
Lalu memberi coding pada cmdIsArray:
Private Sub cmdIsArray_Click()
Dim x As Variant Dim y As Variant
x = Array(“NRP”, “Nama”, “Kelas”) y = “imam cakep”
If IsArray(x) = True Then
MsgBox “Array”, vbOKOnly, “IsArray”
Else
MsgBox “Bukan Array”, vbOKOnly, “IsArray” End If
End Sub
 
Saat program dijalankan, lalu Anda menekan tombol cmdIsArray, maka muncul MessageBox :
Penjelasan :
x = Array(“NRP”, “Nama”, “Kelas”)
Termasuk Array jadi, jika IsArray(x) = Array True
y = “imam cakep”
Tidak termasuk Array jadi, jika IsArray(y) = Array False

Function IsDate
 
Rumus:
IsDate(Expression) As Boolean
Fungsi IsDate berguna untuk mengetahui isi dari objek atau variabel berisi format Date (penanggalan) atau bukan Date. Sebagai contoh. Saya membuat 1 TextBox (txtIsDate) dan 1 CommandButton (cmdIsDate), seperti gambar di bawah :
Lalu memberi coding pada cmdIsDate:
Private Sub cmdIsDate_Click()
If IsDate(txtIsDate.Text) = True Then
MsgBox “Berisi Tanggal”, vbOKOnly, “IsDate”
Else
MsgBox “Tidak Berisi Tanggal”, vbOKOnly, “IsDate”
End If
End Sub
Saat program dijalankan, lalu Anda memasukkan format tanggal atau bukan format tanggal di txtIsDate lalu menekan tombol cmdIsDate, maka muncul MessageBox :
Function IsNumeric
 
Rumus:
IsNumeric(Expression) As Booleanm
Fungsi IsNumeric berguna untuk mengetahui isi dari objek atau variabel berisi angka (number) atau bukan angka. Sebagai contoh. Saya membuat 1 TextBox (txtIsNumeric) dan 1 CommandButton (cmdIsNumeric), seperti gambar di bawah :
Lalu memberi coding pada cmdIsNumeric:
Private Sub cmdIsNumeric_Click()
If IsNumeric(txtIsNumeric.Text) = True Then
MsgBox “Numeric Tao”, vbOKOnly, “IsNumeric”
Else
MsgBox “Bukan Numeric Tao”, vbOKOnly, “IsNumeric”
End If
End Sub
Saat program dijalankan, lalu Anda memasukkan angka atau bukan angka (ex:huruf) di txtIsNumeric lalu menekan tombol cmdIsNumeric, maka muncul MessageBox :
Penjelasan :
txtIsNumeric = 1234
Termasuk Angka atau Numerik, jadi jika txtIsNumeric = True
txtIsNumeric = abcd
Tidak termasuk Angka atau Numerik, jadi jika txtIsNumeric = False

Function CDate
 
Rumus:
CDate(Expression) As Date
Fungsi CDate berguna untuk mengkonversi atau merubah angka menjadi sebuah tanggal. Sebagai contoh. Saya membuat 1 CommandButton (cmdCDate), seperti gambar di bawah :
Lalu memberi coding pada cmdCDate:
Private Sub cmdCDate_Click()
MsgBox CDate(2), vbOKOnly, “CDate”
MsgBox CDate(366), vbOKOnly, “CDate” End Sub
Saat program dijalankan, lalu Anda menekan tombol cmdCDate, maka muncul MessageBox :
Jadi tanggal default atau tanggal awal adalah 31 Desember 1989 [CDate(1)].

Function Hex
 
Rumus: Hex(Number)
Fungsi Hex berguna untuk mengkonversi atau merubah angka desimal (basis 10) angka Hexadecimal atau Hex (basis 16). Sebagai contoh, 1 CommandButton (cmdHex), seperti gambar di bawah :
Lalu memberi coding pada cmdHex:
Private Sub cmdHex_Click()
MsgBox “1 Desimal = Hex ” & Hex(1), vbOKOnly, “Hex” MsgBox “9 Desimal = Hex ” & Hex(9), vbOKOnly, “Hex”
MsgBox “10 Desimal = Hex ” & Hex(10), vbOKOnly, “Hex”
MsgBox “15 Desimal = Hex ” & Hex(15), vbOKOnly, “Hex”
MsgBox “100 Desimal = Hex ” & Hex(100), vbOKOnly, “Hex”
MsgBox “9999 Desimal = Hex ” & Hex(9999), vbOKOnly, “Hex”
End Sub
Saat program dijalankan, lalu Anda menekan tombol cmdHex, maka muncul MessageBox :
Function Space
 
Rumus:
Space(Number As Long)
Fungsi Space berguna untuk memberikan jumlah spasi pada objek yang kita inginkan, kali ini saya memberikan contoh objek pada MessageBox. Sebagai contoh. Saya membuat 1 CommandButton (cmdSpace), seperti gambar di bawah :
Lalu memberi coding pada cmdSpace :
Private Sub cmdSpace_Click()
MsgBox Space(15) & “50 spasi”, vbOKOnly, “Space”
MsgBox Space(100) & “100 spasi”, vbOKOnly, “Space” End Sub
Jika program dijalankan, lalu Anda menekan tombol cmdSpace, maka muncul MessageBox :
 
Penjelasan :
Space(15)
Menampilkan panjang MsgBox dengan 15 spasi
Space(100)
Menampilkan panjang MsgBox dengan 100 spasi
 
Semoga Bermanfaat....!!!
 
Sumber:www.tiforu.org

Belum ada Komentar untuk "Fungsi-Fungsi Dalam Visual Basic 6.0"

Posting Komentar

Electric Smart Cars - Rational Reasons and Results When Buying One There are many reasons for buying any electric smart car, hybrid electric or plugin hybrid electric vehicle. The soaring costs of gas is likely the biggest and most pressing issue when considering buying an electric car. The environment and the planet is another concern. Whatever the reason, buying any BEV, PHEV or green planet-friendly automobile instead of that fossil-fuel burning internal combustion engine car, we'll certainly have a positive effect on helping save the planet and save you money as well. In order to make a smart electric car buying decisions, it is important to understand what the different types of electric-powered vehicles, and how smart electric cars work. There are three types of electric assisted vehicle that utilize an electric motor of some kind. The battery electric vehicle (BEV) is as the name suggests-a battery powered vehicle. There is no other power source for the vehicle, no internal combustion engine (ICE) running on gasoline, and therefore the battery must be charged between uses, and will discharge during use until it runs out. At this point the vehicle can no longer run, so you'll need to be near a charging point before you run out of gas, I mean electric juice. Two types of hybrid electric vehicles offer the best of both the electric and the ICE vehicle worlds. The hybrid electric vehicle (HEV) uses an electric motor to either propel the car or to increase the power. Generally the result of this is to extend the distance that it can travel on a tank of fuel, giving the hybrid electric car better fuel economy. Lastly there is the plug-in hybrid electric vehicle (PHEV). This runs in a largely similar way to the HEV but with one major difference-the battery can be plugged into a charging point, in order to completely charge the battery to its maximum capacity. The HEV by comparison can only charge its battery with the current generated by its ICE, or through regenerative breaking (a process in which energy is reclaimed during breaking rather than lost). By fully charging the battery the use of electrical power can be prolonged, and the use of gasoline reduced, making the PHEV the more economical of the hybrid electric vehicles. The drive-train of a BEV is very simple-a battery powers the motor, which propels the electric vehicle. The hybrid electric vehicles will run an ICE and electric motor either in parallel or in series, with both the ICE and electric motor being able to move the electric or hybrid electric vehicle. A capacitor allows energy to be channeled back into the battery too, and in the case of the PHEV a separate charging circuit like that of the BEV is included to separately charge the hybrid electric vehicle. There are two types of battery that are used in BEV, PHEV and HEV cars. Nickel metal hydride batteries are an older technology, and one that suffers from battery degradation more quickly than others. Newer, lithium-ion batteries are far more efficient, as well as longer lasting in both electric and hybrid electric vehicles. They don't suffer from memory formation like nickel metal hydride batteries, and tend to be able to provide more power for the engine than the alternative. Older hybrid electric vehicles may still use lead-acid batteries, but these are generally now considered bad for the environment, and are no longer used. There are pros and cons to making the move to an electric or hybrid vehicle. They are cheaper to run than ICE cars and have good speed, and hybrid electric vehicles have good range too. But the BEV class can run generally for only up to 40-200 miles, leading to what is known as range anxiety. Hybrid electric vehicles overcome by using the ICE as well, giving vastly superior range. Another downside is that the batteries wear out and need replacing. This is an expensive part on the car, and on a BEV the battery failure means that the car will completely fail to run. A hybrid at least has its ICE on which to fall back. However, the overall running costs to the owner are far less than for a vehicle with an ICE. The electric or hybrid electric vehicle has less moving parts and so less chances of failure that needs repair. Fuel efficiency of a hybrid is hugely increased, saving money for every mile driven, and for a BEV is even less as electrical energy is cheaper than gas. One of the biggest benefits to these vehicles is to the planet. Our oil reserves are finite and dwindling, and their continued use in this way further pollutes the environment. Moving to electric or hybrid electric vehicles will drastically reduce the pollutants emitted, and will slow the rate at which our planet's natural resources are exhausted. As far as the economy is concerned, electric and hybrid vehicles could be very positive development. The production of large numbers of these vehicles would require the building or converting manufacturing factories, and the hiring of workers to staff the factories. Claims are often made that our economy is heavily reliant on oil, and that moving away from it would destroy us, but the truth is quite different. By embracing these technologies, our economy can shift its dependence from oil onto alternatives, just as our motoring needs do. An all-electric or hybrid vehicle may cost a little more to insure than a gas vehicle. Though a small saving is possible thanks to the improved risk profile of people who own electric vehicles, other costs are higher. However, repairing electric or hybrid vehicles currently costs more because there are fewer of these vehicles on the road, and because spare parts are less abundant. This increases repair costs, which insurance companies pass on to owners. Savings in running costs can help offset this. Options are varied when considering purchasing one of these cars, giving potential owners a good range of choice when it comes to the power, size and range of their vehicle. The following are currently available or soon to be released, highway ready environmentally-friendly cars. Full details are not available for some of those cars that are not yet on sale. The Nissan Leaf is an all electric car doing 100 miles per charge and up to 90 mph, and starting at $33,720. This is a modern looking car with a reasonable range, and a competitive pricing. The Tesla Roaster is also all-electric, with an incredible 245 miles per charge, 125 mph top speed, and costs starting at $101,500. This is a stunning looking car with an equally stunning performance-and a range like no other electric car. The Smart-ED all-electric model has a 98 mile maximum range, and a top speed of 60 mph. This small car will be perfect for city driving. Starting at $599 a month for a four year lease. Ford's own all electric car-the Ford Focus has yet to be released but is expected to have a range in excess of 100 miles per charge. This car will be available from late 2011, and looks to provide all of the high-tech options that people may want, in a very stylish exterior. Final price and other details have yet to be released. Chevrolet's Volt is a PHEV that is capable of speeds of 100 mph. Fuel economy depends on how often you charge the battery, with official figures released at 60 mpg using gas and electric combined. Prices start at $32,780, giving this a reasonable price tag along with good performance. Toyota's Prius is a PHEV that has an incredible range of 475 miles on a single tank of gas, when using combined gas and the electric motor. Unfortunately, since it won't be available till early 2012 there are no more details regarding performance and pricing. A full hybrid version of the Toyota Prius is also available, with a base price of $23,520. With a combined mileage of 50mpg and a top speed of 112 mph, it has enough power and efficiency for anyone. This is a tried and trusted hybrid car with a good reputation. Ford's Fusion has a hybrid version as well, with a starting price of $19,820. With a 700 mile range per full tank of fuel, and 41 mpg, it is powerful and sleek, and has the range to take you wherever you want to go. The Escalade hybrid from Cadillac is a luxury SUV, and so it's price tag is a little larger, at $74,135. Fuel efficiency is good for an SUV at up to 23 mpg and a range of up to 575 miles per tank. This SUV balances the needs of a larger family with the desire to be a little more environmentally friendly, and does so with incredible style.

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel