Learn the Rules, Break The Rules, and Create the New Ones...

Hi... My name is Rizky Prihanto. You can call me RQ, or Rizky either. I am currently living on Bandung, Indonesia. Had a lot of works and research about Enterprise Information Systems (majoring on education and e-governments). I have bunch of interests (some friends call it 'freakz') about MySQL Opensource Database and now I am one of the administrator of MySQL Indonesia User Group - the opensource community initialized by Sun Microsystems Indonesia.

My Company PT Cinox Media Insani, Bandung, Indonesia. I work here since 2008 and I take responsibility as Chief of Software Architect. My job is about planning, imaginating, fantasy-ing, concepting, and build the infrastructure of the new information systems (or app engines) which going to be implemented.

This blog This is my blog that represent my current opinion, research and experiences about anything in Software Engineering. Written since 2007 (actually) and has been vaccum for a lot of while. And now I wanna ressurrect this blog (optimistically) from the long-long-hibernation with something fresh and new ideas -- still about MySQL, software engineering, development, and may be something managerial here.

About the tagline I've learned the statement above from some paper written by Kent Beck about Extreme Programming (XP) methodology -- some sort of practical software development methods which have no boundaries. That's very inspiring me a lot. I have written some article on this blog that tell my interpretation about that statement here.

My Another Blogs I have classifying my blogs into some sort of genre. The blog that you read here right now is my primary blog that tell you (majoring) about IT stuff. But if you wanna look another side of me, you can visit here, here, here,or here. Hope it'll be interesting for some of you.

Credits I would thanks to Blogger for this great blog platform. Skinpress who designed this Wordpress template (which is bloggerized by Free Blogger Templates). My appreciate is also going to you who give your generously time for visiting my blog.

Maksain Regional Setting dari VB

Kadang pas kita lagi bikin program yang berhubungan dengan hitung-hitungan, kita sering nemuin masalah yang terkait dengan format penulisan currency. Misal pas kita develop tu program, regional setting kita udah makae Indonesia, jadi display angka currency formatnya makae tanda titik (xxx.xxx.xxx,xx). Eh pas dicoba jalanin di kompie laen yang settingannya default (US English), formatnya berubah jadi koma (xxx,xxx,xxx.yy). Belum lagi kalo ada itung-itungan pecahan. Bisa jadi malah muncul error "invalid property/value" tuh...

Solusinya, bisa aja pakae konversi manual. titik ke koma, trus koma ke titik. di swap gitu lah.. (materi algoritma 101 tuh..). Tapi kadang muncul masalah laen: currency symbol. Pas kita develop, mungkin yg munculnya pake simbol Rp (rupiah). Tapi pas dijalanin di kompie US English, yg muncul malah $. Waah, bisa kachaow beliaow tuh... Atau masalah ini : kadang kan yang berhubungan dengan hitung-hitungan juga berhubungan tuh dengan tanggal. Misal, pembayaran pada tanggal sekian. Pelunasan pada tanggal sekian... Nah, pas kita makae date time picker, format Long Date, koq yg muncul "Friday, 17 August 2007" misalnya.. Wal hasil, dimarahin deh ama client.

Client : "Mas, ngga bisa kah format hari n bulannya diganti makae bahasa Indonesia?".
Kita : "O, bisa pak! Sangat bisa! Bapak tinggal ganti aja regional setting komputer Bapak ke Indonesia. Caranya, masuk ke control panel blablabla...."
kita njelasin sampe beliuran)

Client : "Stop-stop-stop! Koq ribet ya?? Ngga bisa cara gampang kah mas? Wah, klo gtu saya ngga jadi deh beli program penjualan sampeyan. Ntar yang susah malah saya, lagi..."
Kita : "Tapi pak, itu..."
Client : "Nggak! Makasih. Saya udah ngga interest lagi. Bye"
Kita : "Pak...pak... - halo? Pak? -- yaaa, diputus.."

Weleh-weleh... kasian amat kita ya? Hehehe...

Mungkin, cara yang cukup safe utk diterapin supaya dialog via telepon kya di atas ngga kita alamin, adalah dengan men-setting-kan ostosmastis regional setting komputer client. Caranya?

Simak module vb berikut :

'
' ModRegionalSetting.BAS
'

Option Explicit

Const LOCALE_SDECIMAL = &HE ' decimal separator
Const LOCALE_STHOUSAND = &HF ' thousand separator
Const LOCALE_SGROUPING = &H10 ' digit grouping

Const LOCALE_IDIGITS = &H11 ' number of fractional digits
Const LOCALE_ILZERO = &H12 ' leading zeros for decimal
Const LOCALE_SNATIVEDIGITS = &H13 ' native ascii 0-9

Const LOCALE_SCURRENCY = &H14 ' local monetary symbol
Const LOCALE_SINTLSYMBOL = &H15 ' intl monetary symbol
Const LOCALE_SMONDECIMALSEP = &H16 ' monetary decimal separator
Const LOCALE_SMONTHOUSANDSEP = &H17 ' monetary thousand separator
Const LOCALE_SMONGROUPING = &H18 ' monetary grouping

Const LOCALE_ICURRDIGITS = &H19 ' # local monetary digits
Const LOCALE_IINTLCURRDIGITS = &H1A ' # intl monetary digits
Const LOCALE_ICURRENCY = &H1B ' positive currency mode
Const LOCALE_INEGCURR = &H1C ' negative currency mode

Const LOCALE_SDATE = &H1D ' date separator
Const LOCALE_STIME = &H1E ' time separator
Const LOCALE_SSHORTDATE = &H1F ' short date format string
Const LOCALE_SLONGDATE = &H20 ' long date format string
Const LOCALE_STIMEFORMAT = &H1003 ' time format string

Const LOCALE_IDATE = &H21 ' short date format ordering
Const LOCALE_ILDATE = &H22 ' long date format ordering
Const LOCALE_ITIME = &H23 ' time format specifier
Const LOCALE_ICENTURY = &H24 ' century format specifier

Private Declare Function GetSystemDefaultLCID Lib "Kernel32" () As Long
Private Declare Function GetUserDefaultLCID Lib "Kernel32" () As Long
Private Declare Function GetLocaleInfo Lib "Kernel32" Alias "GetLocaleInfoA" (ByVal Locale As Long, ByVal LCType As Long, ByVal lpLCData As String, ByVal cchData As Long) As Long
Private Declare Function SetLocaleInfo Lib "Kernel32" Alias "SetLocaleInfoA" (ByVal Locale As Long, ByVal LCType As Long, ByVal lpLCData As String) As Long

Public DataRegional(11) as string

Private Function GetRegional(nFormat As Long, Optional SetValue As String = -1) As String
Dim vNilai As String, vLcid As Long, Ret As Long
vLcid = GetUserDefaultLCID()
vNilai = Space$(vLcid)
Ret = GetLocaleInfo(vLcid, nFormat, vNilai, Len(vNilai))
If Ret Then
If SetValue <> "-1" Then
Call SetLocaleInfo(vLcid, nFormat, CStr(SetValue))
End If
GetRegional = Left$(vNilai, Ret - 1)
End If
End Function

Public Sub SimpenRegional()
DataRegional(0) = GetRegional(LOCALE_SDECIMAL)
DataRegional(1) = GetRegional(LOCALE_STHOUSAND)
DataRegional(2) = GetRegional(LOCALE_SCURRENCY)
DataRegional(3) = GetRegional(LOCALE_SMONDECIMALSEP)
DataRegional(4) = GetRegional(LOCALE_SMONTHOUSANDSEP)
DataRegional(5) = GetRegional(LOCALE_ICURRENCY)
DataRegional(6) = GetRegional(LOCALE_INEGCURR)
DataRegional(7) = GetRegional(LOCALE_SDATE)
DataRegional(8) = GetRegional(LOCALE_STIME)
DataRegional(9) = GetRegional(LOCALE_SSHORTDATE)
DataRegional(10) = GetRegional(LOCALE_SLONGDATE)
DataRegional(11) = GetRegional(LOCALE_STIMEFORMAT)
End Sub

Public Sub BalikinRegional()
Call GetRegional(LOCALE_SDECIMAL, DataRegional(0))
Call GetRegional(LOCALE_STHOUSAND, DataRegional(1))
Call GetRegional(LOCALE_SCURRENCY, DataRegional(2))
Call GetRegional(LOCALE_SMONDECIMALSEP, DataRegional(3))
Call GetRegional(LOCALE_SMONTHOUSANDSEP, DataRegional(4))
Call GetRegional(LOCALE_ICURRENCY, DataRegional(5))
Call GetRegional(LOCALE_INEGCURR, DataRegional(6))
Call GetRegional(LOCALE_SDATE, DataRegional(7))
Call GetRegional(LOCALE_STIME, DataRegional(8))
Call GetRegional(LOCALE_SSHORTDATE, DataRegional(9))
Call GetRegional(LOCALE_SLONGDATE, DataRegional(10))
Call GetRegional(LOCALE_STIMEFORMAT, DataRegional(11))
End Sub

Public Sub StandardRegionalSetting()
Call GetRegional(LOCALE_SDECIMAL, ",")
Call GetRegional(LOCALE_STHOUSAND, ".")
Call GetRegional(LOCALE_SCURRENCY, "Rp")
Call GetRegional(LOCALE_SMONDECIMALSEP, ",")
Call GetRegional(LOCALE_SMONTHOUSANDSEP, ".")
Call GetRegional(LOCALE_ICURRENCY, 2)
Call GetRegional(LOCALE_INEGCURR, 14)
Call GetRegional(LOCALE_SDATE, "/")
Call GetRegional(LOCALE_STIME, ":")
Call GetRegional(LOCALE_SSHORTDATE, "dd/MM/yyyy")
Call GetRegional(LOCALE_SLONGDATE, "dddd, d MMMM yyyy")
Call GetRegional(LOCALE_STIMEFORMAT, "HH:mm:ss")
End Sub



Naaah, tu module memiliki procedure StandardRegionalSetting yg bisa dipanggil pas Form Utama di initialize, atau pas sebelum itu (di dalam sub main)...

Contoh :

Sub Main()
StandardRegionalSetting
FUtama.show
End Sub


Alhasil, *apapun* regional setting yang di-apply di kompie client, secara otomatis akan berubah ke settingan "standar" sesuai yang kita inginkan..

Tapi mungkin cara ini kurang manusiawi juga. Lha, siapatau emang tu client suka-nya pake US English, coba? Kan kita ngga ngerti motivasinya dia nyetting begituan apa karena emang mbiarin default apa emang karena suka apa cuman Asal British aja?

Nah solusinya, bisa aja kita simpen dulu regional setting dia sebelum njalanin program kita, n ntar klo dia exit : kita balikin regional setting awalnya. Jadi di Sub Main() tadi kita tambahin procedure "SimpenRegional". Lihat code ini :

Sub Main()
SimpenRegional
StandardRegionalSetting
FUtama.show
End Sub


dan pas Form Utama ditutup (FUtama_Unload) panggil procedure "BalikinRegional"

Private Sub FUtama_Unload()
BalikinRegional
End
end sub


Cobain deh...

15 comments:

Anonim mengatakan...

q

Putut mengatakan...

only the one comment --> C E R D A S

Eko mengatakan...

Saya juga mengalami masalah regional setting bolak-balik ditelpon sama user wah ini gimana tampilan angkanya kok ngaco, mudah2 an ini membantu besok saya coba di kompi user, tank's mas Rizky doain mudah2an berhasil

heri mengatakan...

mantabbbbb code nya,,thnks berat

Hilman mengatakan...

Keren bro...
Kebetulan banget nih ..... pas lagi nyari untuk ngerubah regional setting eh ketemu ama ni blog..
Tadinya sih udah ketemu carax ngerubah regional tapi balikinnya blm bisa lagi nyari2, tapi skali lagi berkat sharing nt, ane jadi ga perlu repot lagi nyarinya. thank's a lot ya bro....

Ada lagi ga daftar constant yang lain? untuk setting yang lain lagi?? he...he... maunya.

Jhe mengatakan...

Makasi banyak mas... codingnya emang paten. Problem saya terpecahkan. sekali lg makasi banyak

Anonim mengatakan...

Thanks bro....

Mr.Yani mengatakan...

Matur thank you gan, sampean memang pembawa keselamatan.

Methius Dwijaya mengatakan...

Wah dahsyat nih kodingnya.. bikin ndiri mas?hebat *tepukTangan *tepukTangan saya lagi butuh yang beginian nih,,mantep banget.. makasih ;)

Anonim mengatakan...

thanx tas codingnya..
kebetulan saya juga lagi bermasalah dengan regional seting.....
makasih ya....

Anonim mengatakan...

ini dicopast ke notepad kan kk?

Anonim mengatakan...

terima kasih banyaaakkkk...
kau penyelamatku.

Anonim mengatakan...

system windows untuk proses perhitungan desimal harus titik kalo koma tidak jalan kalo disimpak ke db nilainya digabung 1265824,55 menjadi 126582455 celaka deh
Public Function toNumber(ByVal srcCurrency As String, Optional RetZeroIfNegative As Boolean) As Double
If srcCurrency = "" Then
toNumber = 0
Else
Dim retvalue As String
If InStr(1, srcCurrency, ".") > 0 Then 'Hapus titik
retvalue = Val(Replace(srcCurrency, ",", ".", , vbTextCompare)) 'rubah koma jd titk jadi
Else
retvalue = Val(srcCurrency)
End If
If RetZeroIfNegative = True Then
If retvalue < 1 Then retvalue = 0
End If
toNumber = retvalue
retvalue = 0
End If
End Function

adienz mengatakan...

keren juga gan
ijin nyontek yah :D

Rifki Apriansyah mengatakan...

Gan vb ane ga bisa baca koma nih?? Jd pas muncul angka 9,67 yg di baca malah 9 nya doang. pas diganti ke titik, malah debug. Mohon solusinya gan

Posting Komentar