Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for readini.kix

(view source code of readini.kix as plain text)

  1. ; Check if all required arguments were specified
  2. If $ini = ""
  3. 	GoTo Syntax
  4. EndIf
  5. If $section = ""
  6. 	GoTo Syntax
  7. EndIf
  8. If $key = ""
  9. 	GoTo Syntax
  10. EndIf
  11.  
  12. ; Check if the INI file really exists
  13. If Exist( $ini ) = 0
  14. 	GoTo Syntax
  15. EndIf
  16.  
  17. ; Read the requested value from the INI file
  18. $val = ReadProfileString( $ini, $section, $key )
  19.  
  20. ; Display the result
  21. ? $ini
  22. ? "[$section]"
  23. ? "$key=$val"
  24. ?
  25.  
  26. ; Normal program termination
  27. Exit 0
  28.  
  29.  
  30. :Syntax
  31. ? "ReadINI.kix,  Version 1.01"
  32. ? "Read a value from an INI file"
  33. ?
  34. ? "Usage:  KIX32  READINI.KIX  $$INI=ini_file  $$SECTION=section  $$KEY=key"
  35. ?
  36. ? "Where:           " + Chr(34) + "ini_file" + Chr(34) + " is the file name of the INI file to be read"
  37. ? "                 " + Chr(34) + "section" + Chr(34) + "  is the section name, without the brackets"
  38. ? "                 " + Chr(34) + "key" + Chr(34) + "      is the key whose value must be read"
  39. ?
  40. ? "Arguments that contain spaces should be enclosed in double quotes"
  41. ?
  42. ? "Example: if MYPROG.INI looks like this:"
  43. ? "[Section 1]"
  44. ? "Key1=Value 1"
  45. ? "Key2=Value 2"
  46. ? "[Section 2]"
  47. ? "Key1=Value 3"
  48. ? "Key2=Value 4"
  49. ?
  50. ? "Then the command:  KIX32  READINI.KIX  $$INI=MYPROG.INI  $$SECTION=" + Chr(34) + "section 2" + Chr(34) + "  $$KEY=key2"
  51. ? "should return:     Value 4"
  52. ?
  53. ? "Written by Rob van der Woude"
  54. ? "http://www.robvanderwoude.com"
  55. ?
  56. Exit 1
  57.  

page last modified: 2024-04-16; loaded in 0.0060 seconds