Results 1 to 12 of 12

Thread: [RESOLVED] Need help on how to create a look up form.

  1. #1
    Member
    Join Date
    May 12
    Posts
    37

    Resolved [RESOLVED] Need help on how to create a look up form.

    Hi All,


    Lets say i have a folder which contains some file.{ eg: QHDE.PMB , QDHE.PMD }
    inside these .PMB files, contains some code/data.
    i have copied the code/data into .INI file

    How do i create a form to do look up table ?

    Eg:when i enter "PMB" in a label/text it should extract data from the .INI file and use that as reference for some condition.

    ---------------------------------------------------------------------------

    i need some guide how to create the form and how to link it ?


    Thanks
    Attached Images Attached Images  

  2. #2
    PowerPoster
    Join Date
    Feb 12
    Location
    West Virginia
    Posts
    4,956

    Re: Need help on how to create a look up form.

    Why did you choose to use an INI file?

    An .mdb would seem to make a lot more sense and would make the job of looking up data simple.

  3. #3
    Member
    Join Date
    May 12
    Posts
    37

    Re: Need help on how to create a look up form.

    Quote Originally Posted by DataMiser View Post
    Why did you choose to use an INI file?

    An .mdb would seem to make a lot more sense and would make the job of looking up data simple.

    hi,
    Im still learning VB and not very good in coding. thats y i use INI file. Appreciate if you can guide me. thanks

  4. #4
    PowerPoster
    Join Date
    Feb 12
    Location
    West Virginia
    Posts
    4,956

    Re: Need help on how to create a look up form.

    INI file is not a good choice and would be much harder to do what you seem to need. Database is simple and something that if you do not already know now is a good time to start.

    I would not waste my time trying to make such a thing work with an ini file.

  5. #5
    Member
    Join Date
    May 12
    Posts
    37

    Re: Need help on how to create a look up form.

    Quote Originally Posted by DataMiser View Post
    INI file is not a good choice and would be much harder to do what you seem to need. Database is simple and something that if you do not already know now is a good time to start.

    I would not waste my time trying to make such a thing work with an ini file.
    got it but How do i start for database ?

  6. #6
    PowerPoster
    Join Date
    Feb 12
    Location
    West Virginia
    Posts
    4,956

    Re: Need help on how to create a look up form.

    Well if you have never worked with a database before you should either do a goolge search for VB6 ADO samples or take a look in the codebank.

  7. #7
    Fanatic Member
    Join Date
    Dec 07
    Location
    Albacete, españa
    Posts
    579

    Re: Need help on how to create a look up form.

    Or look through the FAQ's here, specifically for database development. http://www.vbforums.com/showthread.php?t=337051
    A fun card game written in VBA within Excel Tri Peaks

  8. #8
    Member
    Join Date
    May 12
    Posts
    37

    Re: Need help on how to create a look up form.

    hi DataMiser/españolito ,

    i have gone through the forum but i need some time to study/understand it.
    Im running out of time as i need to complete this project as soon as possible n do presentation . thats y i opted to go with .INI first.
    once im done with the presentation, i can study the ADO and change it later

    Any other simple method ? i have attached the pic . thanks
    Attached Images Attached Images  

  9. #9
    PowerPoster
    Join Date
    Feb 12
    Location
    West Virginia
    Posts
    4,956

    Re: Need help on how to create a look up form.

    So show us the code you have written, You say you are using INI files but you have not shown a sample of the INI structure nor any code and a screen shot doesn't do much to help.

    I still think you should be working at using a database. It will not be easy to do this with an INI file and whatever you learn while trying to make this work will not be something that will be likely to be used again, whereas using a proper database would be very useful to you here and in the future.

  10. #10
    Fanatic Member
    Join Date
    Dec 07
    Location
    Albacete, españa
    Posts
    579

    Re: Need help on how to create a look up form.

    I can't help with .ini files, sorry
    A fun card game written in VBA within Excel Tri Peaks

  11. #11
    Member
    Join Date
    May 12
    Posts
    37

    Re: Need help on how to create a look up form.

    Quote Originally Posted by DataMiser View Post
    So show us the code you have written, You say you are using INI files but you have not shown a sample of the INI structure nor any code and a screen shot doesn't do much to help.

    I still think you should be working at using a database. It will not be easy to do this with an INI file and whatever you learn while trying to make this work will not be something that will be likely to be used again, whereas using a proper database would be very useful to you here and in the future.

    Hi,
    i will try to study database. Meanwhile below is the code:
    i manage to create the combo list but how do link it to call INI setting ?



    ------------------------------------------------------------------------------------


    Option Explicit
    Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
    Private Declare Function GetPrivateProfileInt Lib "kernel32" _
    Alias "GetPrivateProfileIntA" _
    (ByVal sSectionName As String, _
    ByVal sKeyName As String, _
    ByVal lDefault As Long, _
    ByVal sFileName As String) As Long

    Private Declare Function GetPrivateProfileString Lib "kernel32" _
    Alias "GetPrivateProfileStringA" _
    (ByVal sSectionName As String, _
    ByVal sKeyName As String, _
    ByVal sDefault As String, _
    ByVal sReturnedString As String, _
    ByVal lSize As Long, _
    ByVal sFileName As String) As Long

    'Scanner data settings
    Private nTotalLengthReceive As Integer
    Private nDataLength As Integer

    'Comm port settings
    Private sSettings As String 'Settings: Baurate,parity,data bit,stop bit; example: Settings=9600,n,8,1
    Private nCommport As Integer
    Private nHandshaking As Integer 'Handshaking: 0:None, 1:XOnXOff, 2:RTS, 3:RTSXOnXOff
    Private nInputMode As Integer 'InputMode: 0:Text, 1:Binary
    Private nInputLen As Integer
    Private nRThreshold As Integer
    Private nSThreshold As Integer
    Private bDTREnable As Boolean
    Private bEOREnable As Boolean
    Private bRTSEnable As Boolean
    Private iTimeOut As Integer

    Private nAutoSaveData As Integer 'Auto save data after how many scan

    Private lCounter As Long
    Private kCounter As Long

    Private nRetry As Integer


    Private st_code As String






    Private Sub Command1_Click()
    List1.Clear
    lCounter = 0
    kCounter = 0
    Label5.Caption = 0
    Label8.Caption = 0

    End Sub

    '****************************************


    Private Sub InitializeHOST()

    With IniFile
    .Path = App.Path & "\PivotInstall.INI"
    .Section = "Options"

    'MSCommVeriCode
    .Key = "HostIP"
    .Default = "10.81.155.104"
    strHostIP = .Value

    .Key = "HostPort"
    .Default = "12100"
    strHostPort = .Value

    End With

    End Sub



    '*****************************************


    Private Sub Command2_Click()
    Dim strTemp As String
    Dim strDirExists As String
    Dim strTodayFile As String
    Dim intFB As Integer
    Dim intcount As Integer

    intFB = FreeFile

    If (List1.ListCount <= 0) Then Exit Sub

    strTemp = App.Path & "\Data"
    strDirExists = Dir(strTemp, vbDirectory)
    If strDirExists = "" Then
    MkDir strTemp
    End If

    strTodayFile = Format(Now, "YYYY_MM_DD") & ".txt"

    strTemp = App.Path & "\Data\" & strTodayFile

    Open strTemp For Append As #intFB

    For intcount = (List1.ListCount - 1) To 0 Step -1
    Print #intFB, List1.List(intcount)
    Next intcount

    Close #intFB

    List1.Clear

    End Sub


    Private Sub File1_Click()

    End Sub

    Private Sub Command3_Click()
    FormDeviceList.Show 1

    End Sub

    Private Sub Form_Load()
    Call LoadSettings
    lCounter = 0
    MSComm1.CommPort = nCommport
    MSComm1.Settings = sSettings
    MSComm1.Handshaking = nHandshaking
    MSComm1.InputMode = nInputMode
    MSComm1.InputLen = nInputLen
    MSComm1.RThreshold = nRThreshold
    MSComm1.SThreshold = nSThreshold

    MSComm1.DTREnable = bDTREnable
    MSComm1.EOFEnable = bEOREnable
    MSComm1.RTSEnable = bRTSEnable
    InitializeHOST


    ShapeResult.BackColor = vbWhite
    LabelPF.Caption = ""


    If (MSComm1.PortOpen = True) Then MSComm1.PortOpen = False
    DoEvents
    Sleep (300)
    MSComm1.PortOpen = True

    End Sub

    Private Sub Form_Terminate()
    If (MSComm1.PortOpen = True) Then MSComm1.PortOpen = False
    End Sub

    Private Sub Form_Unload(Cancel As Integer)
    If (MSComm1.PortOpen = True) Then MSComm1.PortOpen = False
    End Sub



    Private Sub Frame2_DragDrop(Source As Control, X As Single, Y As Single)

    End Sub

    Private Sub MSComm1_OnComm()
    Dim I As Long
    Dim strInput As String
    Dim strEnd As String
    Dim strNow As String

    I = 0
    strInput = ""
    strNow = ""
    Label7.Caption = ""
    Label7.BackColor = vbYellow


    Do
    strInput = strInput & MSComm1.Input
    Text5.Text = strInput
    'DoEvents
    I = I + 1
    'strEnd = Right(strInput, 2) 'Incase want to check Terminal Characters
    Text3.Text = I
    Loop Until (Len(strInput) >= nTotalLengthReceive) Or (I > iTimeOut)










    If I >= iTimeOut Then
    MSComm1.PortOpen = False
    Text1.Text = strInput
    Label7.BackColor = vbRed
    LabelPF = "FAIL VERICODE"
    LabelPF.BackColor = vbRed
    ShapeResult.BackColor = vbRed
    TextErrorMessage.Text = "FAIL VERICODE"
    ' List1.AddItem (strNow & " , " & Text1.Text & " FAIL"), 0 'Add data in List Box
    ' kCounter = kCounter + 1
    ' Label8.Caption = kCounter
    DoEvents
    nRetry = nRetry + 1
    Text4.Text = nRetry
    Else
    If (List1.ListCount >= nAutoSaveData) Then Call Command2_Click 'Auto save data after how many scan
    Text1.Text = Left(strInput, nDataLength)
    Label7.Caption = Left(strInput, nDataLength)
    If Check1.Value = 1 Then
    Clipboard.Clear
    Clipboard.SetText (Label7.Caption)



    End If
    strNow = Format(Now, "YYYY-MM-DD")
    strNow = strNow & " " & Format(Now, "HH:MM:SS") 'Get current Date and Time
    ' List1.AddItem (strNow & " , " & Text1.Text & " PASS"), 0 'Add data in List Box

    ' lCounter = lCounter + 1
    ' Label5.Caption = lCounter
    Label7.BackColor = vbGreen
    LabelPF = "PASS VERICODE"
    LabelPF.BackColor = vbGreen
    ShapeResult.BackColor = vbGreen
    TextErrorMessage.Text = "PASS VERICODE"

    'Call Command6_Click
    Call CheckHSAData(Text1.Text)

    nRetry = 0
    Text4.Text = nRetry
    End If
    Text2.Text = Len(strInput)
    DoEvents
    Sleep (200)
    If (MSComm1.PortOpen = False) Then
    MSComm1.PortOpen = True
    Sleep (200)
    End If
    End Sub

    Private Sub LoadSettings()

    Dim sString As String
    Dim lSize As Long
    Dim iReturn As Integer
    Dim sNull As String
    Dim sFile As String
    Dim strDirExists As String

    sFile = App.Path & "\" & "Settings.ini"
    sNull = Chr$(0)

    'Commport settings
    sString = String$(30, "*")
    lSize = Len(sString)
    iReturn = GetPrivateProfileString("COMM", "Settings", "", sString, lSize, sFile)
    sSettings = Left(sString, (InStr(sString, "*") - 2))

    iReturn = GetPrivateProfileInt("COMM", "Commport", 2, sFile)
    nCommport = iReturn

    'Handshaking: 0:None, 1:XOnXOff, 2:RTS, 3:RTSXOnXOff
    iReturn = GetPrivateProfileInt("COMM", "Handshaking", 2, sFile)
    nHandshaking = iReturn

    'InputMode: 0:Text, 1:Binary
    iReturn = GetPrivateProfileInt("COMM", "InputMode", 0, sFile)
    nInputMode = iReturn

    iReturn = GetPrivateProfileInt("COMM", "InputLen", 2, sFile)
    nInputLen = iReturn

    iReturn = GetPrivateProfileInt("COMM", "RThreshold", 2, sFile)
    nRThreshold = iReturn

    iReturn = GetPrivateProfileInt("COMM", "SThreshold", 2, sFile)
    nSThreshold = iReturn

    iReturn = GetPrivateProfileInt("COMM", "DTREnable", 0, sFile)
    bDTREnable = iReturn

    iReturn = GetPrivateProfileInt("COMM", "EOREnable", 0, sFile)
    bEOREnable = iReturn

    iReturn = GetPrivateProfileInt("COMM", "RTSEnable", 1, sFile)
    bRTSEnable = iReturn

    iReturn = GetPrivateProfileInt("COMM", "TimeOut", 5000, sFile)
    iTimeOut = iReturn

    iReturn = GetPrivateProfileInt("COMM", "AutoSaveData", 20, sFile)
    nAutoSaveData = iReturn

    'Scanner Settings
    iReturn = GetPrivateProfileInt("SCANNER", "TotalLengthReceive", 12, sFile)
    nTotalLengthReceive = iReturn

    iReturn = GetPrivateProfileInt("SCANNER", "DataLength", 8, sFile)
    nDataLength = iReturn


    strDirExists = Dir(App.Path & "\Data", vbDirectory)
    If strDirExists = "" Then MkDir App.Path & "\Data"

    End Sub







    '*********************************************************************************************
    ' // Adding Winsock Connection
    '
    '*********************************************************************************************

    Private Sub WinsockHSA_DataArrival(ByVal bytesTotal As Long)
    ' TCP Socket Data Receive Event
    Dim strTemp As String

    strTemp = ""

    'Start to get data
    WinsockHSA.GetData strTemp, vbString

    'Amend Data
    strTCPHSADataRecv = strTCPHSADataRecv & strTemp

    'Check if all data has been received
    If Len(strTCPHSADataRecv) > 12 Then
    If Len(strTCPHSADataRecv) = Mid(strTCPHSADataRecv, 7, 5) Then
    blnTCPHSADataFinish = True
    End If
    End If

    End Sub

    Private Sub WinsockHSA_Error(ByVal Number As Integer, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean)
    ' TCP Socket Error Event
    blnWinSockHSAError = True
    If WinsockHSA.State <> sckClosed Then
    WinsockHSA.Close
    End If
    DoEvents
    End Sub
    //---------------------------------------------------------------------------------------------

    // I need to add in case statement based on INI at this section

    Private Sub CheckHSAData(ByVal strSN As String)
    Dim strDataBack As String
    Dim fresult As String
    Dim Tem As String

    TextErrorMessage.Text = "Checking HSA Data From Venus-Q server,Please wait for a while"


    strDataBack = QueryHSADataFromServer(TIMEOUT_LENGTH_ACCESS_TO_SERVER, 1, strSN)

    If Mid(strDataBack, 26, 8) = strSN Then


    strDataBack = CStr(Mid(strDataBack, 36, 2))

    If strDataBack = "21" Or strDataBack = "10" Or strDataBack = "" Then
    CurrentDevice.HSAData = "NG"
    CurrentDevice.ResultHSADataPass = False
    Me.ShapeResult.BackColor = vbRed
    Me.LabelPF = "HSA DATA FAIL"
    TextErrorMessage.Text = "HSA Data Fail Or Fail to retrieve HSA Data."

    'Fail Vericode
    Call FinalResult
    End If

    If strDataBack = "00" Then
    CurrentDevice.ResultHSADataPass = True
    CurrentDevice.HSAData = "OK"
    Me.ShapeResult.BackColor = vbGreen
    Me.LabelPF = "HSA DATA PASS"
    TextErrorMessage.Text = "HSA DATA PASS"




    End If


    End If

    End Sub

    //----------------------------------------------------------------------------------------------
    Public Sub FinalResult()

    Dim I As Long
    Dim strInput As String
    Dim strEnd As String
    Dim strNow As String
    Dim strDataBack As String


    If Label7.BackColor = vbGreen = True And Me.LabelPF = "HSA DATA PASS" Then
    Me.ShapeResult.BackColor = vbGreen
    Me.LabelPF = " PASS "
    lCounter = lCounter + 1
    Label5.Caption = lCounter
    strNow = Format(Now, "YYYY-MM-DD")
    strNow = strNow & " " & Format(Now, "HH:MM:SS") 'Get current Date and Time
    List1.AddItem (strNow & " , " & Text1.Text & " PASS" & "," & strDataBack), 0 'Add data in List Box



    Else
    Me.ShapeResult.BackColor = vbRed
    Me.LabelPF = " FAIL "
    kCounter = kCounter + 1
    Label8.Caption = kCounter
    strNow = Format(Now, "YYYY-MM-DD")
    strNow = strNow & " " & Format(Now, "HH:MM:SS") 'Get current Date and Time
    List1.AddItem (strNow & " , " & Text1.Text & ", " & " FAIL " & "," & strDataBack), 0 'Add data in List Box


    End If

    End Sub




    ---------------------------------------------------------------------

    Option Explicit

    Private Sub cmdLoadBomNameCombo_Click()

    Dim intStateFileNbr As Integer
    Dim strBS As String
    ' Dim strStateAbbrev As String
    Dim strStateName As String

    strBS = IIf(Right$(App.Path, 1) = "\", "", "\")
    intStateFileNbr = FreeFile

    Open (App.Path & strBS & "BOM.DAT") For Input As #intStateFileNbr

    cboStateName.Clear

    Do Until EOF(intStateFileNbr)
    Input #intStateFileNbr, strStateName
    cboStateName.AddItem strStateName

    Loop

    Close #intStateFileNbr

    ' MsgBox "BOM list box has been loaded.", _
    ' vbInformation, _
    ' "BOM LIST"

    End Sub

    Private Sub Command1_Click()
    Unload Me
    End Sub

    Private Sub Form_Load()
    Call cmdLoadBomNameCombo_Click

    End Sub

    Private Sub selBOM_Click()

    'cboStateName.AddItem (frmMain.Text6)

    'frmMain.Text6.AddItem (cboStateName) 'Add data in List Box


    Unload Me

    End Sub
    Attached Images Attached Images  

  12. #12
    PowerPoster
    Join Date
    Feb 12
    Location
    West Virginia
    Posts
    4,956

    Re: Need help on how to create a look up form.

    I didn't mean to post your whole project code, just that which is related to reading the ini file along with a sample of the ini file structure you are trying to use.

    btw in the length of time since you first posted till now you could have probably figure dout how to do it with a database and even if not if you wrote some code for it and ran into issues it would be a lot easier to get help as most people would not use an ini file for such a thing nor would they really want to spend the time to try and make an ini work for something like this.

    You could haul groceries back from the store using a tricycle and a wagon but wouldn't it be better to use a car?

Posting Permissions

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