Link to home
Start Free TrialLog in
Avatar of Vlearns
Vlearns

asked on

simple question

i am new to vb:

this is what i want to do

i have a combobox with a list of items:
each of these represent domain names

a1
a2
a3
a4
a5

i also have a command button called  'execute'

now when user selects on either of this , say a1, and hits 'execute' my application needs to go to

C:\WINDOWS\system32\drivers\etc

and add the entry to the hosts file

such as

vv.xx.yy.zz          a1.go.domain.com
vv1.xx1.yy1.zz1   a1.see.domain.com

similarly if user clicks on a2 and hits execute


vv.xx.yy.zz          a1.go.domain.com
vv1.xx1.yy1.zz1   a1.see.domain.com


i now the ip addresses vv.xx.yy.zz etc, so i need to know how to do file handling in vb.


this is what is intend to do...

when user selects one of a1,a2 etc,

backuo hosts to host.bak
delete hosts
create a new file 'hosts' using vb
programmatically write  

vv.xx.yy.zz          a1.go.domain.com
vv1.xx1.yy1.zz1   a1.see.domain.com


to the hosts file

close the file.


please guide me how i can achieve this VB programmatically. i am not familiarwith VB programming constructs.









ASKER CERTIFIED SOLUTION
Avatar of JR2003
JR2003

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of JR2003
JR2003

To access the values in the combobox:

Dim sSelectedItem as String
sSelectedItem  = Combo1.List(Combo1.ListIndex)
Avatar of Vlearns

ASKER

the hosts file should be just 'hosts' and not hosts.txt
do you think the opentextfile can only create the hosts file with hosts.txt?
i will try and see


Avatar of Vlearns

ASKER

got this error

Object Variable or With Block Variable not set

at

.CopyFile "C:\WINDOWS\system32\drivers\etc\hosts", "C:\WINDOWS\system32\drivers\etc\hosts.bak", True

shouldnt fso be initialized to somethin?
Avatar of Vlearns

ASKER


solved the problem:

should have been

Dim fso As New Scripting.FileSystemObject
instead ogf

Dim fso As Scripting.FileSystemObject


Avatar of Vlearns

ASKER


can someone tell me how to write this to file

.WriteLine "123.111.222.333  & Item & .domain.com "

where the output should be

123.111.222.333  ab.domain.com


where Item="ab"  ????????????????????????


<<<<can someone tell me how to write this to file  .WriteLine "123.111.222.333  & Item & .domain.com "

.WriteLine "123.111.222.333 "  &  Combo1.List(Combo1.ListIndex) & ".domain.com"