Anyone have GetEnvironmentVariable working?

BlitzMax Forums/BlitzMax Programming/Anyone have GetEnvironmentVariable working?

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

Here's the code I use (hat tip to Indie)

Function GetEnvironmentVariableA(VarName:Byte Ptr,back:Byte Ptr,size:Short)

Function GetEnvVar:String(VarName:String)
		Local TempBank:TBank = CreateBank(1)
		Local size:Int = GetEnvironmentVariableA(Varname,BankBuf(TempBank),1)
		If size > 0
			ResizeBank(Tempbank,Size+1)
			GetEnvironmentVariableA(Varname,BankBuf(TempBank),Size+1)
		Else
			Return ""
		EndIf
		
		Local tString:String = ""
		Local t:Int
		For t = 0 To BankSize(tempbank)-3
			tString = tString + Chr(PeekByte(tempbank,t))
		Next
		
		ResizeBank(TempBank,0)
		FlushMem()
		Return tString
End Function