Date: 02-16-2022
Return to Index
created by gbSnippets
'The PowerBASIC Environ$ function can be used to access all environment variables
'Environ$ works with a copy of the system environment table, given to the application when it starts.
'Environment data can be accessed by a descriptive string, such as "PathName", or by
'a numerical value. Numerical values differ from PC to PC, but are useful for enumerating
'the entire list of environment variables.
'Primary Code
'Syntax: s$ = ENVIRON$({parameter_string | n})
a$ = Environ$("PathName") 'access single environment value
a$ = Environ$(1) 'access single environment value
Do : Incr x& : a$ = Environ$(x&) : Loop While Len(a$) 'loop through all environment values
'Compilable Example: (Jose Includes)
'uses PowerBASIC function HOST NAME
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "Win32API.inc"
Global hDlg As Dword
Function PBMain() As Long
Dialog New Pixels, 0, "Test Code",300,300,200,200, %WS_OverlappedWindow To hDlg
Control Add Button, hDlg, 100,"Push", 50,10,100,20
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
If CB.Msg = %WM_Command AND CB.Ctl = 100 AND CB.Ctlmsg = %BN_Clicked Then
Local a$, temp$, i as Long
a$ = Environ$("ComputerName") 'access single environment value
MsgBox a$
a$ = Environ$(10) 'access single environment value
MsgBox a$
Do : Incr i : a$ = Environ$(i) : temp$ = temp$ + $crlf + a$ : Loop While Len(a$) 'loop through all environment values
MsgBox temp$
End If
End Function
'gbs_00247
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm