samir_ibrahim 58 Junior Poster

I have this issue which I did not find an answer to it.

I am creating a small app which SUPPOSE to be easy and it is about getting 4 things (User Name, Pc Name, Domain Name, and IP Address)

I have over 35 pc's connected to a domain, and diff user may logged in to a single pc.

I want the ability that my exe could run from network path \\server\folder\myexe.exe instead of copy the file to each pc local HDD.

I create the program and build it, and put the exe on the UNC, I dblclick on it from my pc (Vista), it works fine.

I tried to run the exe from another pc (XP SP2) it gives security warning "Unhandled exception has occurred in your application, if you click continue, the application will ignore this error and attemp to continue. If you click quit, the application will close immediately
Index was outside the bounds of the array.
"

here is original code

Dim wsNet As Object
wsNet = CreateObject("WScript.Network")
txt_UserName.Text = wsNet.UserName
txt_DomainName.Text = wsNet.UserDomain
txt_PcName.Text = wsNet.ComputerName
Dim _HostName = System.Net.Dns.GetHostName()
Dim _IPAdress = System.Net.Dns.GetHostAddresses(_HostName)(0).ToString
txt_IP.Text = _IPAdress

- The above code works fine on my pc (Vista) if I put it on local HDD or UNC
- The above code also works fine on every pc (XP SP2) if copied to local HDD but will give the mentioned error if run from UNC

- …

samir_ibrahim 58 Junior Poster

' Read the whole file to a string
FileText = My.Computer.FileSystem.ReadAllText("D:\account.txt")

I just have one comment.

The above line will read the whole file at once. if the file is big it may lead to memory problem, I prefer to read line by line, I guess my code will be faster on PII with 64mb ram. :D

samir_ibrahim 58 Junior Poster

Hi :)

Never mind from his code, it is lengthy and un-readable :icon_twisted: lol

Just kidding, it is good but I have this small snippet which may help you.

Dim _swFile As System.IO.StreamReader
Dim _Line, _Field As String
' Prepare the file to be read
_swFile = System.IO.File.OpenText("c:\xx.txt")
' Loop the file until end
While Not _swFile.EndOfStream
    ' Read a single line
    _Line = _swFile.ReadLine
    ' Split the line depending on ":"
    If Not IsDBNull(_Line.Split(":")(1)) Then
        _Field = _Line.Split(":")(1)
        Debug.Print(_Field)
    End If
End While

hth

samir_ibrahim 58 Junior Poster

I want to get our remote server's date and time.

One trick I know to get date and time from any machine, is to create a file on that machine (server) and then read the created file date & time.

hth

samir_ibrahim 58 Junior Poster

I normally charge 100$ per hour :D

You are really VERY expensive to take 100$ for 7 line. :-O

I don't want to deal with you any more.

Tell me when you are offline so I can post my question. :D

samir_ibrahim 58 Junior Poster

Account: Apple
Username: Orange
Password: Banana

basically i just want to fill my textboxes with the Apple, Orange and Banana part.

Basically, you did not run or test the code posted by Tame.

Because if you do, you will notice that he has 2 parts, parts 1 reading line by line, and part splitting the line into fields.

Dim FileText As String = "Account: Apple"
Dim FileLines As String()
Dim OneLine As String()
Dim Separator As String = ":"
FileLines = FileText.Split(CChar(Environment.NewLine))
OneLine = FileLines(0).Split(CChar(Separator))
Debug.Print(OneLine(1))

That is a demo of what you have.

Put the above in loop an and your problem is solved.

I hope Tame did not say he want 10$ because I use his approach ;)

samir_ibrahim 58 Junior Poster

I have This function from my framework, and sorry I cannot remember from where I got it, so I am saying that this function is not mine.

I wonder if I did not say the above and owner will came and say "Hey, give me my 10$" :)

Dim RootDir As New IO.DirectoryInfo("F:\Games")
Search(RootDir)
Sub Search(ByVal RootDir As IO.DirectoryInfo)
    For Each File In RootDir.GetFiles("*.mp3")
        Debug.Print(File.FullName) 'process the file
    Next
    For Each SubDir In RootDir.GetDirectories()
        Search(SubDir)
    Next
End Sub

I had tested this function, and it is really VERY fast finding files, but I did not find a way to search for *.mp3 and *.wav at the same time yet.

If I found it, i will post it, if someone knows how, post it as well.

samir_ibrahim 58 Junior Poster

I have tried your code but I'm still unsuccessful. Still can't close form1. form2 closes but not form1.
When I click the Close button it jumps to the closing sub (your code)
but does not close form 1.
Help

I had tried this and works with me.

'in form2.button_click
Me.Close()
Form1.Close()
samir_ibrahim 58 Junior Poster

I have two Issue using a MDI app.
1-at this moment I'm able to open MDI child forms using the MDIparent
except when the I opens form1 I'm also able to open forms 2
and 3 .
but I only want one form to be open at a time.

try to use ShowDialog() instead of Show() or check for TopMost = True

samir_ibrahim 58 Junior Poster

Hi,
How can i pass values from datareader to arraylist

I did not see any arraylist declaration in your code? but you can access the datareader as array if that help.

For I = 1 to objReader.RecordsAffected
    Debug.Print(objReader(I))
Next I
samir_ibrahim 58 Junior Poster

How can you stop IE from opening up in a WebBrowser control on a new window (target=_blank")?

If I understand correctly, you put a WebBrowser control on a form, and when you Issue Navigate it open in IE instead of the form? if that so,

WebBrowser1.Navigate("www.google.com", False)
samir_ibrahim 58 Junior Poster

Controls collection does not have OfType method in .NET 2.0. So I (still) suggest using CType(_oCtrl, CheckBox)

I don't have such experience in diff vb.net versions, I start using vb.net since 6 months only, and I start directly with vb2008

Thank you for your clarification and info, I will keep that in mind in case i need it again.

:)

samir_ibrahim 58 Junior Poster

Hi guys,

i am facing problem when i need to create an excel file and insert some data inside. Can anyone help me? i am using vs 2005 and excel 2003.

Here the way to do it, and you have to explore by your self.

Dim _Ex = New Excel.Application
_Ex.DisplayAlerts = False ' Or True in case you want to see the alerts

Dim _Wb As Excel.Workbook
_Wb = _Ex.Workbooks.Add()

Dim _Ws As Excel.Worksheet
_Ws = _Wb.ActiveSheet

_Ex.Visible = True

' put some data
_Ws.Range("A1").Select()
_Ex.ActiveCell.FormulaR1C1 = "My Data 1"
' or in single line such as
_Ws.Range("A2").FormulaR1C1 = "My Data 2"
' save the excel sheet
_Wb.SaveAs("c:\myexcel.xls")
' quit the excel
_Ex.Quit()
samir_ibrahim 58 Junior Poster

True but :-/

1- It could be a vb.net automated word document and then he want to count them :)

2- If that is a form and the checkbox is static, why don't he count them manually?

3- your code will work just fine if he you want to count the checkbox in a form dynamically, but I suggest using this single line instead of the IF

For Each _oCtrl As Control In Me.Controls.OfType(Of CheckBox)()
    ' ...
Next

Or he can use LINQ

Dim _ling As IEnumerable(Of CheckBox) = From _CheckBoxes In Me.Controls.OfType(Of CheckBox)() _
                                        Where _CheckBoxes.Checked = False _
                                        Select _CheckBoxes
Debug.Print(_ling.Count)

but I am still not sure what he wants to do.

samir_ibrahim 58 Junior Poster

This is a VB.NET forum. I believe that VBA questions belong to DaniWeb's "Visual Basic 4/5/6" forum.

Sorry? I did not understand what you are trying to say to me?

samir_ibrahim 58 Junior Poster

The checkboxs you show are displayed in word document or in vb form?

samir_ibrahim 58 Junior Poster

Correct me if I am wrong maheshsayani or anyone else, but using a command object used that way will not return a recorset....

I am sure you know that the result of command.execute is record set. so may be explain your question more?

As I did not understand the PO question, I did not on which back end he talking about. does he mean a SP in SQL Server or a normal function in vb he is calling it stored procedure.

samir_ibrahim 58 Junior Poster

displayListBox1 is the name of the listbx containing the data I need to use in my LINQ inquiry. thank you.

If you want to use LINQ, I guess there is no need to store the value off the Listbox in array.

Dim _Linq As IEnumerable = From _ListBoxItems In Me.ListBox1.Items _
                           Select _ListBoxItems
For Each _Item In _Linq
    Debug.Print(_Item)
Next
samir_ibrahim 58 Junior Poster

I was quite sure that WMI has some way to find out remote machine names.
for only those IPs that do response to ping?

Actually I don't think so.

The ping itself is slow, I had tried to ping with many ways.
#1

_PingReply = My.Computer.Network.Ping(_IP)

#2

_oPings = _oWMI.ExecQuery("Select * from WIN32_Pingstatus where address='" + _IP + "'")

#3

_oWSH = CreateObject("Wscript.shell")
 _DOS = "cmd /c ping -n 1 -w 1 192.168.0." & I.ToString
_PingReply = _oWSH.Run(_DOS, 0, True)

#4

IF _NetInfoPing.Send("192.168.0." + I.ToString).Status = Net.NetworkInformation.IPStatus.Success Then

The ping should wait and get the response, and that makes it slow to enumerate all the IP address in range (1-255)

I guess I will change the way , I will try to find a way to list all online pc on LAN (workgroup or domain) and then resolve it is name.

I will post back if I got a faster result.

samir_ibrahim 58 Junior Poster

I was quite sure that WMI has some way to find out remote machine names.
for only those IPs that do response to ping?

Actually I don't think so.

The ping itself is slow, I had tried to ping with many ways.
#1

_PingReply = My.Computer.Network.Ping(_IP)

#2

_oPings = _oWMI.ExecQuery("Select * from WIN32_Pingstatus where address='" + _IP + "'")

#3

_oWSH = CreateObject("Wscript.shell")
 _DOS = "cmd /c ping -n 1 -w 1 192.168.0." & I.ToString
_PingReply = _oWSH.Run(_DOS, 0, True)

#4

IF _NetInfoPing.Send("192.168.0." + I.ToString).Status = Net.NetworkInformation.IPStatus.Success Then

The ping should wait and get the response, and that makes it slow to enumerate all the IP address in range (1-255)

I guess I will change the way , I will try to find a way to list all online pc on LAN (workgroup or domain) and then resolve it is name.

I will post back if I got a faster result.

samir_ibrahim 58 Junior Poster

I managed to get this code, it works but it is slow.

Dim _oWMI, _IP, _oPings,_PcName
_oWMI = GetObject("winmgmts:")
For I = 1 To 255
    _IP = "192.168.0." + I.ToString
    _oPings = _oWMI.ExecQuery("Select * from WIN32_Pingstatus where address='" + _IP + "'" + " and ResponseTime > 0")
    For Each oPing In _oPings
        _PcName = System.Net.Dns.GetHostEntry(_IP)
        Debug.Print(_IP & Chr(9) & _PcName.HostName)
    Next
Next I
samir_ibrahim 58 Junior Poster

Can anybody please help me with the code to read file names inside a zip file using VB6. I am able to open(not extract) the zip file.

I use this code to read information about files stored in zip

Dim oShellApp As New Shell32.Shell
Dim ZipFileName As String
ZipFileName = "c:\myfile.zip"
For Each oFile In oShellApp.NameSpace(ZipFileName).Items
    Debug.Print(oFile.Name)
    Debug.Print(oFile.Type)
    Debug.Print(oFile.ModifyDate)
    Debug.Print(oFile.IsFileSystem)
    Debug.Print(oFile.IsFolder)
    Debug.Print(oFile.Path)
    Debug.Print(oFile.Size)
Next
samir_ibrahim 58 Junior Poster

I have a working code in VFP, I try to convert to Vb.Net and It gives error, I got the help from Dave Kreskowiak from code project. and here it is the working code

' Add a panel to the form
' Form Declaration 
Private Declare Auto Function SetParent Lib "user32" (ByVal hwndChild As IntPtr, ByVal hwndParent As IntPtr) As IntPtr
' Button1_Click
Dim p As Process = Process.Start("Excel.exe")
p.WaitForInputIdle()
SetParent(p.MainWindowHandle, Panel1.Handle)

It is not error tested and should be controlled more.

hth

samir_ibrahim 58 Junior Poster

hi,
Is there any way to rewrite this code using a loop?

Does vb.net have something similer to the pointers used in C++?
thank you.

Try this for reducing code in your example.
I don't know C++ so I cannot answer your question about pointer.

Dim nTotal As Double
For Each oTextBox As Object In Me.Controls
    If TypeOf (oTextBox) Is TextBox Then
        If Not IsNumeric(oTextBox.Text) Then
            MessageBox.Show("Please enter numerical value")
            oTextBox.clear()
            oTextBox.Focus()
            Exit Sub
        End If
        nTotal = nTotal + oTextBox.Text
        lblTotal.Text =nTotal.ToString
    End If
Next
samir_ibrahim 58 Junior Poster

Thank you for reply,
Actually I am using file element for uploading image in html

The above is Upload

Can any one help me , how to send the image file from html to vb.net..

The above is Download

Make your mind and ask a clear question.

samir_ibrahim 58 Junior Poster

hi.. thx for ur reply guyzzz... i solved my problem..
thx guyzz

Hi,

Glad you solved your problem.

I need 2 things from you if posiible

#1 mark this thread as solved
#2 post the time that you populate the listview in first approach and the second one.

TIA.

samir_ibrahim 58 Junior Poster

Hi,

I had a suggestion for you.

You are filling the Listview from table and function (which use table)

I suggest that you create new rs which will hold all your required data and then fill the listview from the rs.

hth

samir_ibrahim 58 Junior Poster

Just curious

What do you want to name it?

samir_ibrahim 58 Junior Poster

your syntax was written in .net. hahahah....

It is vb6 but I did not know what is [ code=What? ] [ /code ] to write in vb6 syntax :)

do u have any vb code to share?

Actually I don't have any vb code to share.

The above 2 examples are my code in Visual foxpro, and I convert them to vb6 when I saw this message :)

please support this thread even it 2 year old posted. ^_^

Did you try the above example and they did not work?

What do you need to know more ?

samir_ibrahim 58 Junior Poster

I did not notice that this post is 2 years old.

Should I delete my answer?

samir_ibrahim 58 Junior Poster

I can think of 2 function that could able to help you.
#1 Printing by IE
#2 Print Any kind of File

' #1 Print By IE

Dim oIE
Dim FileName
FileName = "c:\myfile.txt" ' or .html or .xml depending on where you stored the data you want to print
oIE = CreateObject("InternetExplorer.Application")
oIE.Visible = True ' You can change this to False
oIE.Navigate2 (FileName)
While oIE.ReadyState <> 4
Wend
oIE.ExecWB 6, 0  ' Print
'oIE.ExecWB 7, 0 ' Print Preview

#2 PrintFile Function

Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
    (ByVal hwnd As Long, _
     ByVal lpOperation As String, _
     ByVal lpFile As String, _
     ByVal lpParameters As String, _
     ByVal lpDirectory As String, _
     ByVal nShowCmd As Long) As Long
 FileName = "c:\myfile.txt" ' Any kind of file (xls doc xml html )
 nRetVal = ShellExecute(0, "Print", FileName, "", "", 0)
samir_ibrahim 58 Junior Poster
shell "cmd.exe /c dir \"

Could not you find a shorter one? :D

Nice Code

samir_ibrahim 58 Junior Poster

Do you want fires with the finished project ?

samir_ibrahim 58 Junior Poster

- Google Search CutePDF
- Download and Install it (it is free)
- That will create a PDF printer
- open the PDF File using VB and Acrobat reader
- Send the file to CutePDF printer from page 1 to page 1
- Send the file to CutePDF printer from page 2 to page 2 etc...

hth

samir_ibrahim 58 Junior Poster
Dim oWSH
Dim cmdDOS As String
Set oWSH = CreateObject("WScript.Shell")
cmdDOS = "cmd.exe /c "
cmdDOS = cmdDOS & "DIR *.*"
oWSH.Run cmdDOS, 1
'Change the 1 to 0 if you don't want to see the dos window
samir_ibrahim 58 Junior Poster

I did some research and here is my result
#1 subitem image is no longer supported in listview for vb.net
http://social.msdn.microsoft.com/forums/en-US/winforms/thread/355566d9-5b17-4654-ab78-61394713c05c/
#2 you can use the vb6 listview and use the reporticon
http://www.vbforums.com/showthread.php?t=25032
#3 search google for "vb.net OAKListView"
http://www.codeproject.com/KB/list/OAKListView.aspx?display=PrintAll

hth

Ramy Mahrous commented: Great links +6
samir_ibrahim 58 Junior Poster

Hi Comatose

When dealing with servers (which are usually important to the company) the safest way to move the database, is to duplicate it first....

That is not necessary.
De-Attach and Attach are safe method and you can do it with no fear of data lost unless the database you want to move has a replication.

then later remove it from the source. So while you are right, moving and duplicating are different.... would you think it is wise from an administration point of view to move the data? No. You duplicate the data... then if everything goes well, you delete the old data.

I agree, always take a backup before doing such thing

There is three kind of copying/duplicating the DB from one server to another. Backup/Restore,De-attach/Attach, Copy Directly from source to destination.
Each one has it is own characteristics and depends on the situation(error in replication, server hardware failure, etc..) he should choose which one he should use.

So, assuming we are people who have server administration experience (could be a big assumption), I'd say it's a safe bet to not even talk about the act of "moving" data directly.........

I have Microsoft certificate in MSSQL Server Admin in 2003 ad I have 8 years of experience in SQL Server Administrator :)

Comatose commented: Nice Response +10
samir_ibrahim 58 Junior Poster

As per the logic of execution your code, if you want to fill the array in let say button_1 click and then use the array in another sub, you have to declare the array in the form declaration not in the same sub. or else you will be able to use that Array?

' Form1 Declaration
Dim aCandidate(0) As String

' sub Button6_Click
Dim I As Integer
I = UBound(aCandidate, 1) + 1
ReDim Preserve aCandidate(I)
aCandidate(I) = InputBox("Enter the candidates name:", "candidatename", "", 500, 500)
samir_ibrahim 58 Junior Poster

How to move (or Duplicate) a Microsoft SQL Server Database from One Physical Server to another server (like backup) in vb.net 2.0 ?

First, Move is totally different from Duplicate
Move is deleting DB from first server and put it is second server
Duplicate is both server having the same DB
So,
First you choose which one you want (Move or Duplicate)
Second, you want to do that by vb.net coding or manual?

samir_ibrahim 58 Junior Poster

I will speak on my self when I say I did not understand how your array should work, and I guess that is the reason why you did not got an answer so far, so I suggest the following
- you already post your pseudo-code so we know you had tried :)
- I suggest posting algorithm of what you want (by words not by code)

samir_ibrahim 58 Junior Poster

Hi
I guess I have a lot to learn and suffer.

I just hope I don't explode before I finish my first project. :)

samir_ibrahim 58 Junior Poster

Does it matter if 'all' or 'most' are supported? .

Yes it matter to me

I am learning vb.net, so when some vb.net guy say some info, I cannot argue with him because I don't have the knowledge yet.

How the above is matter?
#1 I did not know if it is bad or good to use API calls in vb.net, but after I found many code sample still using API I begin to wonder.

#2 copying my foxpro or vb6 code and paste it in vb.net without changing or finding replacement for the API calls because it will run, so I will not bother myself seeking for vb.net way

#3 I know now that the code will run at same efficiency even it was in API or .Net Libraries. So the saying "using .net function" is always better is not true?

What are you trying to point out with that.....? (the same on your #1 question about experienced programmers)...

I am moving from foxpro to vb.net . It is not an easy job for me to do so, I am reading as much I can but I will give you 2 example

Once I post a question about how to find how many occurrence of first string in the second string. I search google and all function I found is minimum 6 line and some has 30 lines just to …

samir_ibrahim 58 Junior Poster

Thank you Ramy for your reply

I know API are still supported, but my question was Is "ALL" API calls are included? I guess most of them.

Microsoft Win32 to Microsoft .NET Framework API Map

.NET Framework Class Library Namespace List

samir_ibrahim 58 Junior Poster

Hi Every one

As I am still in the learning curve of vb.net I have 2 Question

1- Before I as start learning vb.net I know vb6 (good) and visual foxpro (Professional). In these 2 languages every thing that cannot be handled with there native command, I use win32 API calles to accomplish my job, then some expert programmer who knows both c# and foxpro mention that in .Net there is no need to use COM server such FileSystemObject or API calls anymore in any .Net Languages since they are internally integrated in .net Libraries.

I am seeing to much VB.Net code that is still using API calls and few which is still using the COM Object.

My #1 question, Is all these examples posted by not very experienced programmers so they still use what they know from vb6 or it is true that all API functions is included in the .Net Libraries?

My #2 Questioin: Where I can find the list of all .Net Libraries Function (AFAIK almost 3600 Functions) ?

TIA

samir_ibrahim 58 Junior Poster

This is really for Beginner like you and me :)

http://www.homeandlearn.co.uk/NET/vbNet.html

samir_ibrahim 58 Junior Poster

I am using HelpNDoc Personal, free and work gr8

http://www.portablefreeware.com/?id=1233

samir_ibrahim 58 Junior Poster

Well, Any thing can be done by Foxpro can be done in vb.net also

Try this code

Dim oAccess As Object
        'Create Access Database
        oAccess = CreateObject("Access.Application")
        oAccess.NewCurrentdatabase("c:\myaccess.mdb")

        'Create Table
        Dim tdf As New DAO.TableDef
        Dim fld As New DAO.Field
        Dim db As Object
        db = oAccess.CurrentDb
        tdf = db.CreateTableDef("MyTable")
        'Create Field MyField as long
        Dim dbLong As Integer
        dbLong = 4
        fld = tdf.CreateField("MyField", dbLong)
        tdf.Fields.Append(fld)
        db.TableDefs.Append(tdf)
        oAccess.Visible = True
samir_ibrahim 58 Junior Poster

Hi,
If I understand, you want to create a restaurant application and you don't have a base knowledge.

I guess you have 2 solution

#1 Go to a restaurant holding a paper and pen, and start asking question about how the operation flows and then create your app
#2 Download many demo restaurant software, and take an idea of how they work.

My advice? is #1 First then #2 then #3 which is start creating your application

Comatose commented: Great Response +9
samir_ibrahim 58 Junior Poster

You are Very Welcome.

samir_ibrahim 58 Junior Poster

you could create a flag such as Dim bIsCodeNeedToRunTrue As Boolean and set to true when you want the code in the cobbobox_selected_indexchanged to be executed and to false when not.

or you could transfer the code from the cobbobox_selected_indexchanged to click() and this way you can control if you want to the code need to be run or no, if you change the combo by mouse the code will run , if you change the code programming, you can issue

ComboBox.Text = ds.tables(0).rows(0).item(0)
ComboBox.click() ' or remove this line for not executing the code

hth