Skip to content

SETENVIRON


设置系统环境变量

语法

declare function Setenviron ( byref varexpression as string ) as long

用法

result = Setenviron( varexpression )

参数

varexpression

以下列(或等效)形式表示的环境变量名称和值:varname=varstring。

(varname 为环境变量的名称,varstring 为要设置的文本值)

返回值

成功时返回零(0),否则返回非零值。

说明

修改系统环境变量。除系统默认的变量外,还有几个其他可编辑的变量。例如 fbgfx,可以通过它选择 FreeBASIC 图形库使用的图形驱动程序形式。

示例

start GeSHi

'e.g. to set the system variable "path" to "c:":

Shell "set path" 'shows the value of path
SetEnviron "path=c:"
Shell "set path" 'shows the new value of path

end GeSHi

start GeSHi

vb
  '' WINDOWS ONLY EXAMPLE! - We just set the graphics method to use
  '' GDI rather than DirectX (or Direct2D added on new systems).
  '' You may note a difference in FPS.
SetEnviron("fbgfx=GDI")

  '' Desktop width/height
Dim As Long ScrW, ScrH, BPP
ScreenInfo ScrW, ScrH, BPP

  '' Create a screen at the half width/height of your monitor.
  '' Normally this would be slow, but GDI is fairly fast for this kind
  '' of thing.
ScreenRes ScrW/2, ScrH/2, BPP

  '' Start our timer/
Dim As Double T = Timer

  '' Lock our page
ScreenLock
Do
 
    '' Print time since last frame
  Locate 1, 1
  Print "FPS: " & 1 / ( Timer - T )
  T = Timer
 
    '' Flip our screen
  ScreenUnlock
  ScreenLock
    '' Commit a graphical change to our screen.
  Cls
 
Loop Until Len(Inkey)

  '' unlock our page.
ScreenUnlock

end GeSHi

平台差异

  • 在 Linux 中,varexpression 必须是持久的(字面量、在主代码中声明的变量或在过程中声明的静态变量),因为 Linux 不会记忆字符串本身,只记录指向其数据字符的指针。

与QB的区别

  • 在 QB 中,Setenviron 被称为 Environ

参见

  • Environ
  • Shell

返回 目录

基于 FreeBASIC 官方文档翻译 如有侵权请联系我们删除
FreeBASIC 是开源项目,与微软公司无隶属关系