is this possible ?


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: is this possible ?

  1. #1
    Join Date
    May 2008
    Posts
    37

    Question is this possible ?

    everytime we have a new account type we have to mod the source code as follows :

    Code:
    do while fnum(eof)=false
     line input cmne$, acct_type$
     select case acct_type
      case "T84" : acct_prod="SP"
      case "T14" : acct_prod="SW"
      case "T15" : acct_prod="NOS"
      case "T16" : acct_prod="SUN"
     end select
    loop
    now i want to read the conditions and values from a text file rather than editing the source :

    Code:
    do while fnum(eof)=false
      line input cmne$, acct_type$
      do while pnum(eof)=false
       line input atype$, aprod$
       if atype$ then
          aprod$
          exit do
       endif
      loop
    loop
    wherein the text file where i read atype$,aprod$ would contain the following :
    "acct_type$="T84"","acct_prod="SP""
    "acct_type$="T14"","acct_prod="SW""

    such that all now i have to do is edit my text file always rather the modify and recompile ...

    is this possible ?

    thanks in advance ...
    BASED FROM YOUR POSTS, I HAVE EXAMINED YOUR BEHAVIORAL PATTERN AND I SAW YOUR BRAIN'S TWO SIDES : LEFT & RIGHT, AND I SAW THAT ON THE LEFT SIDE THERE'S NOTHING RIGHT WHILE ON THE RIGHT SIDE THERE'S NOTHING LEFT

  2. #2
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    Try this: First, create a file (accttypes.txt) that looks like this:
    Code:
    T84,SP
    T14,SW
    T15,NOS
    T16,SUN
    Next, add a reference in your project to the Microsoft Scripting Runtime (scrrun.dll). Now create a function that reads the text file and populates a Dictionary:
    Code:
    Private Function LoadAccountTypes(ByVal FileName As String) As Scripting.Dictionary
    
        Dim hFile As Integer
        Dim sText As String
        Dim Values() As String
        Dim AccountTypes As Scripting.Dictionary
        Set AccountTypes = New Scripting.Dictionary
    
        hFile = FreeFile
        Open FileName For Input As hFile
        Do Until EOF(hFile)
            Line Input #hFile, sText
            If Len(sText) > 0 Then
                Values = Split(sText, ",")
                AccountTypes.Add Values(0), Values(1)
            End If
        Loop
        Close hFile
    
        Set LoadAccountTypes = AccountTypes
    
    End Function
    Finally, modify your code to use the Dictionary to convert acct_type to acct_prod:
    Code:
    Dim AccountTypes As Scripting.Dictionary
    Set AccountTypes = LoadAccountTypes("d:\path\accttypes.txt")
    
    Do While fnum(EOF) = False
        Line Input cmne, acct_type
        acct_prod = AccountTypes(acct_type)
    Loop
    Phil Weber
    http://www.philweber.com

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center