CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Country Codes

  1. #1
    Join Date
    Apr 2001
    Location
    USA
    Posts
    28

    Country Codes

    Hello Everybody!!!
    I need some help:
    How do I get all the country codes from Windows I mean, the phone code.
    I have to do a combo box with it.
    I know I can do that with API, but I do NOT know how.
    Can someone help me, please?
    Thaks in advance


  2. #2
    Join Date
    Jan 2001
    Posts
    165

    Re: Country Codes

    Make a new form with a sorted combo box named Combo1 then paste this code into the form.

    private Type VBRASCTRYINFO
    CountryCode as Long
    CountryID as Long
    CountryName as string
    NextCountryID as Long
    End Type

    private Declare Function RasGetCountryInfo _
    Lib "rasapi32.dll" Alias "RasGetCountryInfoA" _
    (lpRasCtryInfo as Any, lpdwSize as Long) _
    as Long

    private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _
    (Destination as Any, Source as Any, byval Length as Long)
    '_______________________________________________________________

    private Function VBRasGetCountryInfo _
    (clsCountryInfo as VBRASCTRYINFO) as Long

    Dim b(511) as Byte, lpSize as Long, rtn as Long
    Dim lPos as Long, strTemp as string, lngLen as Long
    b(0) = 20
    CopyMemory b(4), clsCountryInfo.CountryID, 4
    lpSize = 512

    rtn = RasGetCountryInfo(b(0), lpSize)

    VBRasGetCountryInfo = rtn
    If rtn <> 0 then Exit Function

    CopyMemory clsCountryInfo.NextCountryID, b(8), 4
    CopyMemory clsCountryInfo.CountryCode, b(12), 4

    CopyMemory lPos, b(16), 4
    lngLen = lpSize - lPos - 2

    If lngLen > 0 then
    strTemp = string(lngLen, 0)
    CopyMemory byval strTemp, b(lPos), lngLen
    End If

    clsCountryInfo.CountryName = strTemp
    End Function

    private Sub Form_Load()
    Dim lngID as Long, rtn as Long
    Dim MyCountry as VBRASCTRYINFO
    lngID = 1

    Do
    MyCountry.CountryID = lngID
    rtn = VBRasGetCountryInfo(MyCountry)

    Combo1.AddItem (MyCountry.CountryName & " (" & MyCountry.CountryCode & ")")

    If rtn <> 0 then Exit Do

    lngID = MyCountry.NextCountryID
    Loop While lngID <> 0

    Combo1.ListIndex = 0
    End Sub



    Code complements of PlatformVB
    http://home.iprimus.com.au/billmcc/P...ountryinfo.htm

    -K


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured