Search content:

 

Personal Menu
Username:
Password:
Save password

Become a member

Forgot Password?

 

Don't miss these
Random Sprite Swap
True Lingo Color Wheel 1.0
Reset Cursor of all sprites to Default
Dave Client
Behavior Writer
Authorware 5 Attain Authorized
simInetPro Xtra
OnStage DVD for Director
Generic Slider w/Text
OpenDocument
MediaMacros Xtras Mall
 

 

 

Behavior ini-script

Added on 8/6/1999

 

Compatibilities:
D6_5 D7 D8 PC Script

This item has not yet been rated

Author: JonLeuven

Reads a fields from a ini-file using fileIO-Xtra this script uses a text-field to store the ini-file content. So you have to make a dummy text-field called "inifield".

-- made by Jon van Leuven
-- last update: 23-07-99

-- methods:

-- fileToField( filename  )
--     read a file and put it into a field (field "inifield")
-- fieldToFile( filename )
--     put field into a file (field "inifield")
-- readIniField( sectionName, itemName )
--     get a value from an ini-field
-- writeIniField( sectionName, itemName, value )
--     store a value to an ini-field
-- read( filename )
--     get ascii data from file
-- write( filename, data )
--     write ascii data to a file

on fileToField filename  
  set myFile = new (xtra "fileio")
  set rightFile = filename
  
  -- use the searchPaths to search the right ini-file
  repeat with n = 1 to the length of the searchPaths
    set fullPath = getAt( the searchPaths, n ) & filename
    openFile(myFile, fullPath, 1)
    set error = error( myFile, status( myFile ) )
    if( error <> "OK" ) then
      set rightFile = fullPath
    end if
    closeFile(myFile)
  end repeat
  
  put read( rightFile ) into field "inifield"
end

on fieldToFile filename
  set myFile = new (xtra "fileio")
  set rightFile = filename
  
  -- use the searchPaths to search the right ini-file
  repeat with n = 1 to the length of the searchPaths
    set fullPath = getAt( the searchPaths, n ) & filename
    openFile(myFile, fullPath, 1)
    set error = error( myFile, status( myFile ) )
    if( error <> "OK" ) then
      set rightFile = fullPath
    end if
    closeFile(myFile)  
  end repeat
  
  write( rightFile, field "inifield" )
end


on readIniField sectionName, itemName
  set sectionFlag = FALSE
  set fieldName = "inifield"
  set the itemDelimiter = "="
  
  repeat with n = 1 to the lineCount of member fieldName
    -- read and process line
    set oneLine = line n of field fieldName
    if( charToNum( char 1 of oneLine ) = 10 ) then
      set oneLine =  chars( oneLine, 2, length( oneLine ) )
    end if
    
    --put oneLine
    
    if( sectionFlag = FALSE ) then
      --section detected
      if( char 1 of oneLine = "[" ) then
        set sec =  chars( oneLine, 2, length( oneLine )-1 )
        if( sec = sectionName ) then
          set sectionFlag = TRUE
        end if
      end if
    else
      --item detected
      if( item 1 of oneLine = itemName ) then
        return item 2 of oneLine
      end if
    end if
  end repeat
end

on writeIniField sectionName, itemName, value
  set sectionFlag = FALSE
  set the itemDelimiter = "="
  set fieldName = "inifield"
  
  repeat with n = 1 to the lineCount of member fieldName
    -- read and process line
    set oneLine = line n of field fieldName
    if( charToNum( char 1 of oneLine ) = 10 ) then
      set oneLine =  chars( oneLine, 2, length( oneLine ) )
    end if
    --put oneLine
    
    if( sectionFlag = FALSE ) then
      --section detected
      if( char 1 of oneLine = "[" ) then
        set sec =  chars( oneLine, 2, length( oneLine )-1 )
        if( sec = sectionName ) then
          set sectionFlag = TRUE
        end if
      end if
    else
      --item detected
      if( item 1 of oneLine = itemName ) then
        set updatedLine = numToChar( 10 ) & item 1 of oneLine & "=" & value
        put updatedLine into line n of field fieldName
      end if
    end if
  end repeat
end

on read filename
  set myFile = new (xtra "fileio")
  openFile(myFile, fileName, 1)
  
  -- check for error
  set error = error( myFile, status( myFile ) )
  if( error <> "OK" ) then
    alert( filename & " - file error: " & error )
    return
  end if
  
  set data = readFile(myFile)
  
  closeFile(myFile)
  return data
end

on write filename, data
  set myFile = new (xtra "fileio")
  openFile(myFile, fileName, 2)
  
  -- check for error
  set error = error( myFile, status( myFile ) )
  if( error <> "OK" ) then
    alert( filename & " - file error: " & error )
    return
  end if
  
  writeString( myFile, data )
  closeFile(myFile)
end

 


Upload Provided by ABCUpload ASP

Contact

MMI
22 West Court Sq
Suite 2C
Newnan, GA 30263
USA

Fax - (206) 339-5833

Send e-mail