You are not logged in.

Dear visitor, welcome to Jabaco - Community. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

OlimilO

Intermediate

  • "OlimilO" is male
  • "OlimilO" started this thread

Posts: 277

Date of registration: Jan 18th 2009

Location: Germany

Occupation: software engineer

  • Send private message

1

Saturday, January 31st 2009, 2:11pm

Environ

Hello everywhere,

maybe you know the function Environ in VB6 where you can get system variables.

e.g. the windows-directory or the temp-path.

Environ has the following Syntax:

Environ({envstring | number})

The Environ function syntax has these named arguments:

Source code

1
2
3
4
5
6
7
8
9
10
11
Part                       Description 
_________________________________________________ 
envstring Optional. String expression containing 
                             the name of an environment variable. 

number Optional.   Numeric expression corresponding to the 
                             numeric order of the environment string 
                             in the environment-string table. 
                             The number argument can be any numeric 
                             expression, but is rounded to a whole 
                             number before it is evaluated.


in VB6 you can use this function like in the following code snippet:

Form:
CommandButton: Command1
ListBox: List1
TextBox: Text1, Text2

Jabaco Source

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
Private Sub Command1_Click() 
   Dim X As Integer 
   Dim Buffer As String 
   For X = 1 To 34 
      Buffer = Environ$(X) 
      If Len(Buffer) <> 0 Then 
         List1.AddItem Buffer 
      End If 
   Next 
End Sub 
Private Sub List1_Click() 
   Dim s As String: s = List1.List(List1.ListIndex) 
   Dim sa() As String: sa = Split(s, "=") 
   Text1.Text = sa(0) 
   'here again we ask the Environ-function to see the difference between 
   'calling it with a number and with a string 
   Text2.Text = Environ(sa(0)) 
End Sub


afair this function is not availible in the Jabaco framework until now:

Jabaco Source

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
Option Explicit
Private Sub Command1_Click()
   
   Dim i As Integer
   Dim Buffer As String
    
   For i = 1 To 34
      Buffer = Environ(i)
      If Buffer <> Nothing Then
         List1.AddItem Buffer
      End If
   Next
   
End Sub
Public Sub List1_Click()
   Dim s As String = List1.List(List1.ListIndex)
   Dim sa() As String
   sa = Split(s, "=")
   Text1.Text = sa(0)
   ' here again we ask the Environ function to see the difference 
   ' between calling it with a number or with a string
   Text2.Text = Environ(sa(0))
End Sub
Public Function Environ(var) As String
   Dim se As String
   Dim vt As VBVarType
   
   vt = VarType(var) 
   If vt = vbString Then
      se = CStr(var)
   Else
      Dim v As Integer
      v = CInt(var)
      Select Case v
      Case 1: se = "ALLUSERSPROFILE"
      Case 2: se = "APPDATA"
      Case 3: se = "CLASSPATH"
      Case 4: se = "CLIENTNAME"
      Case 5: se = "CommonProgramFiles"
      Case 6: se = "COMPUTERNAME"
      Case 7: se = "ComSpec"
      Case 8: se = "FP_NO_HOST_CHECK"
      Case 9: se = "HOMEDRIVE"
      Case 10: se = "HOMEPATH"
      Case 11: se = "INCLUDE"
      Case 12: se = "LANG"
      Case 13: se = "LIB"
      Case 14: se = "LOGONSERVER"
      Case 15: se = "NUMBER_OF_PROCESSORS"
      Case 16: se = "OS"
      Case 17: se = "Path"
      Case 18: se = "PATHEXT"
      Case 19: se = "PROCESSOR_ARCHITECTURE"
      Case 20: se = "PROCESSOR_IDENTIFIER"
      Case 21: se = "PROCESSOR_LEVEL"
      Case 22: se = "PROCESSOR_REVISION"
      Case 23: se = "ProgramFiles"
      Case 24: se = "QTJAVA"
      Case 25: se = "SESSIONNAME"
      Case 26: se = "SystemDrive"
      Case 27: se = "SystemRoot"
      Case 28: se = "TEMP"
      Case 29: se = "TMP"
      Case 30: se = "USERDOMAIN"
      Case 31: se = "USERNAME"
      Case 32: se = "USERPROFILE"
      Case 33: se = "VSCOMNTOOLS"
      Case 34: se = "windir"
      End Select
   End If
Try: On Error Goto Catch   
   If se <> Nothing Then
      If vt = vbString Then
         Environ = System.getenv(se)
      Else
         Environ = se & "=" & System.getenv(se)
      End If
   Else
      Environ = Nothing
   End If
   Exit Sub
Catch:   
   Environ = Nothing
End Function




greetings

OlimilO

This post has been edited 2 times, last edit by "OlimilO" (Feb 1st 2009, 5:17am)


OlimilO

Intermediate

  • "OlimilO" is male
  • "OlimilO" started this thread

Posts: 277

Date of registration: Jan 18th 2009

Location: Germany

Occupation: software engineer

  • Send private message

2

Sunday, February 1st 2009, 5:19am

edited

I have edited it

there was a minor syntax bug

OlimilO

Intermediate

  • "OlimilO" is male
  • "OlimilO" started this thread

Posts: 277

Date of registration: Jan 18th 2009

Location: Germany

Occupation: software engineer

  • Send private message

3

Monday, September 14th 2009, 11:30pm

Hi @ll



i read here System that the getEnv-function is marked as deprecated.

We could also use the function getProperty.

Jabaco Source

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
Dim Text1 As TextBox
Public Sub Form_Load()
   Text1 = New TextBox
   Text1.FontName = "Courier New"
   Text1.FontSize = 10
   Text1.Visible = True
   Me.add Text1   
   ShowProperties   
End Sub
Public Sub ShowProperties()
   Dim keys As java#util#Enumeration = System.getProperties.keys
   Dim keyList As New java#util#ArrayList
   While keys.hasMoreElements
      keyList.add keys.nextElement
   Wend
   Call java#util#Collections.sort(keyList)
   Dim skeys() As String
   Redim skeys(0 To keyList.size - 1)
   Dim key As String, value As String
   Dim sBuffer As New java#lang#StringBuffer
   For i = 0 To keyList.size -1
      key = Cast(keyList.get(i), String)
      value = System.getProperty(key)
      If value = vbCrLf Then value = "&H1310"
      sBuffer.append(key).append(" = ").append(value).append(vbCrLf)
   Next
   Text1.Text = sBuffer.toString   
End Sub
Public Sub Form_Resize() 
   Dim W: W = Me.ScaleWidth
   Dim H: H = Me.ScaleHeight
   If W > 0 And H > 0 Then
      Text1.Move 0, 0, W, H
   End If
End Sub



greetings OlimilO

This post has been edited 1 times, last edit by "OlimilO" (Sep 15th 2009, 4:30pm)


Rate this thread
WoltLab Burning Board