samir_ibrahim 58 Junior Poster

You can embed Excel and Word inside vb/c# form. I also suffered alot to get a working a code where I found alot of posts says that web browser can embed excel but that did not work with me

Here is my way

Add a Form, Button, Panel
This will display Excel inside the panel

Add Refrence to : Microsoft Office ?? Object Library

Imports Microsoft.Office.Interop

Public Class Form1
    Declare Auto Function SetParent Lib "user32.dll" (ByVal hWndChild As IntPtr, ByVal hWndNewParent As IntPtr) As Integer
    Declare Auto Function SendMessage Lib "user32.dll" (ByVal hWnd As IntPtr, ByVal Msg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
    Private Const WM_SYSCOMMAND As Integer = 274
    Private Const SC_MAXIMIZE As Integer = 61488
    Private Sub btnShowExcel_Click(sender As Object, e As EventArgs) Handles btnShowExcel.Click
        Dim sExcelFileName = "C:\myfolder\myexcel.xlsx"
        Dim oExcel As New Excel.Application
        oExcel.DisplayAlerts = False
        oExcel.Workbooks.Open(sExcelFileName)
        oExcel.Application.WindowState = Excel.XlWindowState.xlMaximized
        oExcel.Visible = True

        SetParent(oExcel.Hwnd, pnlExcel.Handle)
        SendMessage(oExcel.Hwnd, WM_SYSCOMMAND, SC_MAXIMIZE, 0)
    End Sub
End Class
samir_ibrahim 58 Junior Poster

There could be some security restriction if you install the access database in c:\program file\your_folder or c:\program file (x86)\your_folder . If you do, try to to give full access to the folder where your data reside by right click on the folder and press properties >> security tab.

samir_ibrahim 58 Junior Poster

You are using 2 Tables, reading the row of the first table, then reading all the rows of second table, but you are not using any value from any row in any table

In your IF CONDITION you have (IF TEXTBOX.TEXT = STRING), the table rows loop is useless if you not reading the value from tables..

So, what you are trying to do exactly?

samir_ibrahim 58 Junior Poster

your query will not return the columns name "locid,locname,locadd", it will return 1 column as you put in the query

your only column is MAX(locid), and since you didnot specify the a name by using MAX(locid) as FieldName, its hard to tell what will be the column name.

You are getting 1 column contains Max(locid), so to get it correctly

dtr.Read()
xt_locid.Text = dtr(0).ToString

and remove the other two since they don't exist.

samir_ibrahim 58 Junior Poster

sqlda.SelectCommand = sqlcmd -- the error is pointing here

How did you declared sqlda and salcmd?
there should be in your declaration Dim sqlda as New ...... and Dim sqlcmd as New ....

samir_ibrahim 58 Junior Poster

Try this
Remove the msgbox()
put this line instead

if cmbAssocID.SelectedValue Is Nothing then Exit Sub
samir_ibrahim 58 Junior Poster

I believe that you had used SQLClient() and you should use
SqlServerCe.SqlCeConnection

Try that.

samir_ibrahim 58 Junior Poster
Dim ServerName = "pc_name"
Dim AdminUserName = "Administrator"
Dim DomainName = "domain_name"
Dim AdminPassword = "password"
' Initialize WMI
Dim objSWbemLocator As New WbemScripting.SWbemLocator
' Connect to remote PC


Dim objSWbemServices = objSWbemLocator.ConnectServer _
                       (ServerName, "root\cimv2", _
                       AdminUserName, AdminPassword, _
                       "MS_409", "ntlmdomain:" + DomainName)


Dim Drive,Path,FileName,Ext as String

Drive = chr(34) + "c:" + Chr(34)
Path = chr(34) + "\\newfolder\\" + chr(34)  
FileName = chr(34) + "test" + chr(34) 
Ext = chr(34) + "txt" + chr(34) 

 Dim oCIM_DataFile = objSWbemServices.ExecQuery _
                     ("select * from CIM_DataFile where drive = " & Drive _ 
                     & " and path = " & Path & " and filename = " & FileName _ 
                     & " and extension = " & Ext)

For Each obj In oCIM_DataFile
    ' If your program execution got here, then the file exist
    Debug.Print (obj.FileName)
Next
samir_ibrahim 58 Junior Poster

I have saved the column name as 'Serial No' with quotes also in the name,only beacause of the space issue

Very nice from you.

Are you aware that putting the field name between quotes is INVALID ?

samir_ibrahim 58 Junior Poster

I begin recently large excel automation & manipulation project. and I have vs2008 and office 2007

First, I note that when I use HDR=YES in the connection string, it ask for ISAM driver so I omit it and my connection string became like this.

Dim _xls_loc = "c:\test.xls"
Dim _xls_cnn_str As String = "Provider=Microsoft.Jet.OleDb.4.0;data source=" & _xls_loc & ";Extended Properties=Excel 8.0;"

Second, you have to decide how you want to deal with the sheet name as a table, it is kinda tricky. I know 3 ways

select * from [sheet1$]
Select * From [sheet1$A1:B10]

or this one which i am currently using, create a Name for the excel range you want to use. in excel 2007 you have to go Formulas >> Define Name after you select the range you want to use and give it a name, then you can use this name in the excel as select * from mynamedexcel Don't forge to use [] when dealing with field name contains spaces such as [Serial No] not 'Serial No'

try this

ast_liab_excelcmd.CommandText = "UPDATE [AssetsLiabilities$] SET " & ast_liab_updatecmd1 & " WHERE [Serial No] = '" & TextBox1.Text & "'"

this is a good site for Excel ADO & automation
http://www.homeandlearn.co.uk/excel2007/excel2007s7p6.html

hth

samir_ibrahim 58 Junior Poster

I agree with sknake that you can use MSSQL 2005/2008 Express Edition as a server and multiple clients/user can connect to it.

You have to take into consideration that in express edition the DB size limit is 4GB and you cannot use it as publisher for replication.

For more info.
http://www.microsoft.com/sql/prodinfo/features/compare-features.mspx?PHPSESSID=0324345d45ef1bf1f764044e03584cd0

samir_ibrahim 58 Junior Poster

Glad that you solve your problem.

Could you please mark the thread as solved?

Have a nice day.

samir_ibrahim 58 Junior Poster

First check this http://support.microsoft.com/kb/905719

When you issue Me.Close() the form still reside in the memory and the object inside it are still exist (not destroyed)

Try this
in the button that close the Dialog put this
Me.Close()
Msgbox(Me.Text) <-- this will give you the name of the of the form but you close it?

now try this

Me.Dispose()
MsgBox(Me.Text) <-- the Dispose will release the form and all it is object.

hth

samir_ibrahim 58 Junior Poster

How you are opening/closing the second form? post code.

samir_ibrahim 58 Junior Poster

What is your db back-end?

samir_ibrahim 58 Junior Poster

Try this

SELECT Training.EmpID, Training.TrainingType, Employee.EmpName, EmpProfInfo.Des_ID, Designation.Designatio
FROM Designation RIGHT OUTER JOIN
Employee RIGHT OUTER JOIN
EmpProfInfo RIGHT OUTER JOIN
Training ON EmpProfInfo.EmpID = Training.EmpID ON Training.EmpID = Employee.EmpID ON Designation.Des_ID = EmpProfInfo.Des_ID
WHERE (Training.TrainingType <> 'Type1')

samir_ibrahim 58 Junior Poster

Guess what happened?!

You got infected and did you not create the anti-virus yet? ;)

Any help will be appreciated!

Help with what exactly? The above is correct. does it give any error?

samir_ibrahim 58 Junior Poster

The site is changed, and the text below which you are searching for "</span></b></font></span>" is no more available.

Good luck.

samir_ibrahim 58 Junior Poster

As fast response, you have 2 things missing
Inet <-- is not declared
DivideText <-- which i guess it is a function is not there is your code.

You can stick with your code, and you can use my code if you find it better

Dim xmlHTTP
Dim URL As String
Set xmlHTTP = CreateObject("MSXML2.XMLHTTP")
URL = "http://www.perceler.com/getipadr1.php"
xmlHTTP.Open "GET", URL, False
xmlHTTP.Send
Debug.Print xmlHTTP.responseText
BillWebber commented: Nice of him to offer me some help. Thank you. +3
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 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 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

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

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

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

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
samir_ibrahim 58 Junior Poster
Dim iAge, iWeight As Integer
iAge = Val(TextBox1.Text)
iWeight = ((iAge - 1) * 3) + 11

hth

Samir Ibrahim