1
1
Fork 0
mirror of https://github.com/QB64-Phoenix-Edition/QB64pe.git synced 2024-07-05 21:40:25 +00:00
QB64-PE/internal/help/ENVIRON$.txt

100 lines
5.5 KiB
Plaintext

The '''ENVIRON$''' function returns a [[STRING]] environmental value from the PC's environmental settings list.
{{PageSyntax}}
::: setting$ = ENVIRON$({''list_number%''|''systemID$''})
* The function can use an [[INTEGER]] ''list_number'' order value or [[STRING]] ''systemID$'' parameter.
* ''List_number'' refers to the number order of the environmental list. Returns are not in any particular numerical order.
* ''SystemID'' is the specific [[STRING]] parameter requested. Returns that environmental [[STRING]] setting only:
::* "BLASTER" returns current Sound Blaster settings if installed.
::* "COMPUTERNAME" returns OEM serial number of the PC.
::* "HOMEPATH" returns current user's Administrator or "OWNER" folder path.
::* "OS" returns the Windows Operating System version.
::* "PATH" returns full Windows path settings
::* "PROGRAMFILES" returns path to Program files folder normally "C:\PROGRAM FILES"
::* "PROMPT" returns current OS prompt setting. Windows 95 and 98 had version in brackets "[WIN 98]$P$G"
::* "SYSTEMROOT" returns the absolute path to the Windows folder including the drive letter. Normally "C:\WINDOWS"
::* "TEMP" returns path to TEMP folder. Normally "C:\TEMP"
::* "USERNAME" returns the current Administrator name or "OWNER".
: ''Note:'' There are other possible system settings that are not listed! Run ''Example 1'' to see the list on your computer.
* The OS in Win 9X or ME can be found in the "PROMPT" parameter ID. Returns are limited in Win 9X and ME.
* ''Note:'' '''QB64''' may not return the same environment list as Qbasic or SET does in DOS.
''Example 1:'' Viewing the list of environmental parameter settings using a counter loop like SET does in DOS.
{{CodeStart}} '' ''
{{Cl|DO}}
i = i + 1
setting$ = {{Cl|ENVIRON$}}(i) ' get a setting from the list
{{Cl|PRINT}} setting$
{{Cl|IF...THEN|IF}} i {{Cl|MOD}} 20 = 0 {{Cl|THEN}} {{Cl|PRINT}} "Press a key": {{Cl|SLEEP}}: {{Cl|CLS}}
{{Cl|LOOP}} {{Cl|UNTIL}} setting$ = ""
{{CodeEnd}}
''Example 2:'' Creating a shortcut on a user's desktop for QB64.EXE using the program's icon. Must be run in program's folder to work!
{{CodeStart}}
'=== Enter the EXE file and ICON or BMP image for the shortcut.
Program$ = "QB64.EXE" '<<<<<<<<<< Enter the '''exact''' program name for shortcut
ICON$ = "QB64ICON.BMP" '<<<<<<<<<< Enter icon or bitmap to use from program's folder
DeskTopShortcut Program$, ICON$
{{Cl|END}} '====== END DEMO CODE ======
{{Cl|SUB}} DeskTopShortcut (Program$, ICON$)
f = {{Cl|FREEFILE}}
{{Cl|SHELL}} {{Cl|_HIDE}} "CD > PRGMDIR.INF" 'get the current program path
{{Cl|OPEN}} "PRGMDIR.INF" {{Cl|FOR (file statement)|FOR}} {{Cl|INPUT (file mode)|INPUT}} {{Cl|AS}} #f
{{Cl|LINE INPUT (file statement)|LINE INPUT}} #f, PATH$
{{Cl|CLOSE}} #f
{{Cl|KILL}} "PRGMDIR.INF"
PATH$ = PATH$ + "\": FILE$ = PATH + Program$
PRINT PATH$ 'DEMO print
A$ = {{Cl|ENVIRON$}}("HOMEDRIVE") '=== Get Current User setting from Environment.
B$ = {{Cl|ENVIRON$}}("HOMEPATH")
C$ = A$ + B$ 'shortcut to user's desktop if found
{{Cl|IF...THEN|IF}} C$ = "" {{Cl|THEN}} C$ = {{Cl|ENVIRON$}}("ALLUSERSPROFILE") 'try desktop for all users
PRINT C$ 'DEMO print
URLFILE$ = {{Cl|MID$}}(Program$, 1, {{Cl|INSTR}}(Program$, ".")) + "URL" 'change EXE to URL
{{Cl|IF...THEN|IF}} C$ > "" {{Cl|THEN}}
SHORTCUT$ = C$ + "\Desktop\" + URLFILE$ 'create filename for the desktop
{{Cl|ELSE}} SHORTCUT$ = PATH$ + URLFILE$ 'if all else fails put in program folder
{{Cl|END IF}}
PRINT SHORTCUT 'DEMO print
{{Cl|OPEN}} SHORTCUT$ {{Cl|FOR (file statement)|FOR}} {{Cl|APPEND}} {{Cl|AS}} #f
{{Cl|IF...THEN|IF}} {{Cl|LOF}}(f) {{Cl|THEN}} {{Cl|CLOSE}} #f: {{Cl|EXIT SUB}} '=== if filesize is NOT Zero don't overwrite!
Q$ = {{Cl|CHR$}}(34) '=== Write URL Shortcut file info.
{{Cl|PRINT (file statement)|PRINT}} #f, "[InternetShortcut]" 'URL type
{{Cl|PRINT (file statement)|PRINT}} #f, "URL=" + Q$ + "file://" + FILE$ + Q$ 'URL program file
{{Cl|PRINT (file statement)|PRINT}} #f, "WorkingDirectory=" + Q$ + PATH$ + Q$ 'Working path
{{Cl|PRINT (file statement)|PRINT}} #f, "IconIndex = " + Q$ + "0" + Q$ '0 is first index
{{Cl|PRINT (file statement)|PRINT}} #f, "IconFile = " + Q$ + PATH$ + ICON$ + Q$ 'Icon path in working folder
{{Cl|CLOSE}} #f
{{Cl|END SUB}} '' ''
{{CodeEnd}}
{{small|Adapted from code by Dav}}
: ''Explanation:'' The SUB program finds the current program's path and user's desktop path. It then creates the shortcut on the desktop with a program icon. The custom icon should be in the program's folder. If an environmental path is not found, the shortcut is placed in the program's folder. The SUB can be added to any program.
<center>{{Text|'''NOTE:''' A temorary file named PRGMDIR.INF is created and deleted.|darkred}}</center>
''See also:''
* [[_DEVICES]], [[_DEVICE$]]
* [[_LASTBUTTON]], [[_OS$]]
* [[ENVIRON]] {{text|(statement)}}
* [[Windows Environment]]
* [[Windows Libraries#Windows User|Windows User Paths Library]]
{{PageNavigation}}