|
Hello Experts!!!
I am declaring array arr() as string
assign values to array...now i want to search specific content in that array.Can anybody tell me how will i do this?
|
|
|
|
|
If you want to search for a String within an array of Strings you can use this function.
Private Function indexInArray(ByVal theArray As String(), ByVal value As String) As Integer
For i As Integer = 0 To theArray.Length - 1
If theArray(i) = value Then Return i
Next
Return -1
End Function
To use this function you have to pass the array you want the string to be searched in and the string you want to search (value).
This function will return -1 if it doesn't find the string you want to search within the array. If it does find it it returns the index. NOTE: This only works for one-dimensional arrays.
You can use this sub to test it.
Private Sub testIt()
Dim myStrings(1) As String
myStrings(0) = "hello"
myStrings(1) = "world"
If indexInArray(myStrings, "hello") <> -1 Then
MessageBox.Show("The string in contained within the array")
End If
End Sub
|
|
|
|
|
Thanx for reply but in function
If theArray(i) = value Then Return i //doesn't return i after finding index value same with value,it return -1 for all values
|
|
|
|
|
How exactly are you using the function?
It should be :
indexInArray(the array you are working with, "value to search")
|
|
|
|
|
Hi,
there is an Array.Find(Of T) method in recent .NET versions. You can give it a predicate that explains what exactly is a find. I haven't used it yet.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
|
Hi there,
I'm creating a menu system (using visual basic 2008 express) used to fire off other applications (not .net) in the same window. I've found source code relating to the issue so that the fired off application opens up, then it finds the window by the process name ("process" here) and changes it so it is a child of the vb form window. This works a treat, however when it is minimized in the vb (parent) window It cannot be restored:
Private hchild As IntPtr
Private hParent As IntPtr
Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, _
ByVal lpWindowName As String) As IntPtr
Private Declare Function SetParent Lib "user32.dll" (ByVal hWndChild As IntPtr, _
ByVal hWndNewParent As IntPtr) As IntPtr
..................................................................
process.Start()
Threading.Thread.Sleep(1000)
hchild = FindWindow(vbNullString, "process")
If hchild.ToInt32 <> 0 Then
hParent = SetParent(hchild, Me.Handle)
End If
I can still see the minimised application but cannot select it. Any help or a point in the right direction to a general overview on the subject (I did look but couldn't find anything, well much that made much sense to me) would be greatly appreciated!
|
|
|
|
|
First of all, you don't need the Thread.Sleep, or the FindWindow. Use process.WaitForInputIdle(1000) instead of Thread.Sleep for a more intelligent waiting algorithm
Next, you can replace the result of FindWindow with process.MainWindowHandle . This mains you don't have to call FindWindow at all. You may, however want to consider what happens if a process has more than one window open (hint: try EnumChildWindows)
Lastly, which application are you talking about? If it's the minimised application, then you can use ShowWindow for that
Between the idea
And the reality
Between the motion
And the act
Falls the Shadow
|
|
|
|
|
On top of what Computafreak said, you'll have to supply a either a button in your host app or a menu option to restore the window. Since you already have the window handle (MainWindowHandle property of the Process object), all you need to do is call ShowWindow[^] and give it the appropriate window handle and window state values.
|
|
|
|
|
Hi all,
Hope someone can help. I am maintaining a web service and having downloaded from VSS and compiled the service when I run it it fails. I have located the problem but cannot explain it or resolve it.
The code is attempting to read database connection information from the web.config file but what is being returned from the code
System.Configuration.ConfigurationSettings.AppSettings("server")
System.Configuration.ConfigurationSettings.AppSettings("catalog") etc.
is "nothing", literally! Does anyone have any idea why this might be happening? Any help would be greatly appreciated.
Thanks in advance, J
|
|
|
|
|
Is the config file in the same folder as the page that is trying to read it?? Are you sure you don't have more than one copy of the web.config file in the app? If you get "nothing" from these statements, it's because there either is no web.config file where it is supposed to be, is named improperly, or the XML document in the file is not written correctly.
|
|
|
|
|
Hi Dave,
Thanks for the reply. All yours points makes sense but none of them seem to be the reason behind my particular problem. This is a web service as well so it's not a page accessing the web.config file. The config file itself is in the correct folder and having reviewed the XML in the config file it appears to be correct.
Any other suggestions, at this stage, would be very welcome.
Thanks again, J
modified on Friday, July 10, 2009 5:15 AM
|
|
|
|
|
Hi all,
anyone knows how can I store a file into a blob field in Oracle? I'm using VB 2008 and adodb (v. 2.8) and oracle ver.9.2.0.1.0 I tried with some example downloaded from internet, but no one works fine. Any suggestion will be really appreciate.
Below you can see an example found in internet:
Public sub ImportFile(ByVal sFile as string)
Dim rs = New ADODB.Recordset
Dim st = New ADODB.Stream
rs.Open("Select * from doc_allegati where matricola = " & gMatricola, oConn, ADODB.CursorTypeEnum.adOpenKeyset, ADODB.LockTypeEnum.adLockOptimistic)
st.Type = ADODB.StreamTypeEnum.adTypeBinary
st.Open()
st.LoadFromFile(sFile)
With rs
.AddNew()
.Fields("ID").Value = 1
.Fields("Documento").Value = st.Read
.Update()
End With
rs.close
st.close
end sub
This not work; when I try to open the recordset vb give me back an error message such as: 'data type not supported'
Thaks in advance for your help,
Filippo
|
|
|
|
|
Lucky me - I don't use Oracle at all.
But, a quick Google reveals a bunch of possiblities. Results...[^]
|
|
|
|
|
Hi Dave,
you are right, but into the example I need to use ODP.NET. Is it possible to manage this kind of field without install this?
Thanks,
Filippo
|
|
|
|
|
So, you looked at one example that used ODP.NET. There are others in that list that use other database providers that work with Oracle.
Filippo1974 wrote: Is it possible to manage this kind of field without install this?
Keep reading through the results list and find out. This is what is called "research", and it's an integral part of any programming job.
|
|
|
|
|
Hi,
We have 'Primary Interop Assemblies' folder at the following path:
"C:\Program Files\Microsoft.NET\Primary Interop Assemblies"
How can we install them? or with which product we get these assemblies installed? any help would be greatly appreciated
Thank you,
Raheem MA
|
|
|
|
|
Primary Interop Assemblies would be supplied by the application that you want to interact with, such as Office 2003 or 2007. You can also download the PIA's seperately from Microsoft and run their installer.
|
|
|
|
|
Here is the IDL definition
[
object,
uuid(DAFB7D76-0158-452F-8FD0-FF97A683DEA3),
helpstring("ITest Interface"),
pointer_default(unique)
]
interface ITest : IUnknown
{
[helpstring("method GetString")] HRESULT GetString([out,retval] BSTR* pVal);
};
[
uuid(E768DC15-A19B-407C-ACF9-C420D6FDB1BE),
version(1.0),
helpstring("TestServer 1.0 Type Library")
]
library TESTSERVERLib
{
importlib("stdole32.tlb");
importlib("stdole2.tlb");
[
uuid(788571BD-030B-49CC-8C0A-2DF74E58331A),
helpstring("Test Class")
]
coclass Test
{
[default] interface ITest;
};
};
The ATL COM Library uses APARTMENT threading model.
And the VB.NET windows service code fragment
try
Dim obj As New TESTSERVERLib.Test
Dim s As String
s = obj.GetString()
Catch ex As Exception
WriteToLog(ex.Message)
WriteToLog(ex.InnerException.ToString)
End Try
When the code executes the following error occurs:
Unable to cast COM object of type 'TESTSERVERLib.TestClass' to interface type 'TESTSERVERLib.ITest'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{DAFB7D76-0158-452F-8FD0-FF97A683DEA3}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).
Object reference not set to an instance of an object.
But the same code works in VB.NET forms application.
Can anyone please explain the reason.
|
|
|
|
|
It appears that the problem comes down to the threading apartment model being used in your service app and your Windows Forms app. They appear to use different models.
You can check this by calling Thread.CurrentThread.AparmentState . It's either going to be STA ot MTA. Your COM component requires one threading model, and gets it under the Windows Forms app, but the service is using the other threading model.
|
|
|
|
|
The Apartment model in the VB.NET windows service is MTA. Whereas in the VB.NET forms application it is STA.
I experimented another method. I wrote a ATL component of type IDispatch interface. It works in both VB.NET forms application as well as VB.NET windows service.
The VB.NET windows service which I am going to write for my customer is a COM library using APARTMENT threading model. QueryInterface fails for all interfaces of type IUnknown. Can you elaborately explain the hidden details of why QueryInterface of type IUnknown fails in a VB .NET windows service and help me to make it work!
Thanks in Advance.
|
|
|
|
|
I have no idea. The internal working of COM are not my strong suit.
|
|
|
|
|
how can i connect crystal report to sql server with vb.net code ? i don know how to make connection for it. can u give me some example of making crystal report connection?
|
|
|
|
|
|
If you just want to update your connection settings (dbname / loginid / loginpass) this code will do:
Private Function reconnectreport(ByVal report As ReportDocument, ByVal servernaam As String, ByVal dbnaam As String, ByVal dbLogin As String, ByVal dbPass As String) As ReportDocument
Try
Dim connection As IConnectionInfo
Dim oldServerName As String = report.DataSourceConnections(0).ServerName
Dim newServerName As String = servernaam
Dim oldDatabaseName As String = report.DataSourceConnections(0).DatabaseName
Dim newDatabaseName As String = dbnaam
Dim userID As String = dbLogin
Dim password As String = dbPass
report = report
' Change the server name and database in main reports
For Each connection In report.DataSourceConnections
If (String.Compare(connection.ServerName, oldServerName, True) = 0 _
And String.Compare(connection.DatabaseName, oldDatabaseName, True) = 0) Then
' SetConnection can also be used to set new logon and new database table
report.DataSourceConnections(oldServerName, oldDatabaseName).SetConnection( _
newServerName, newDatabaseName, userID, password)
End If
Next
' Change the server name and database in subreports
Dim subreport As ReportDocument
For Each subreport In report.Subreports
For Each connection In subreport.DataSourceConnections
If (String.Compare(connection.ServerName, oldServerName, True) = 0 _
And String.Compare(connection.DatabaseName, oldDatabaseName, True) = 0) Then
' SetConnection can also be used to set new logon and new database table
subreport.DataSourceConnections(oldServerName, oldDatabaseName).SetConnection( _
newServerName, newDatabaseName, userID, password)
End If
Next
Next
Return report
Catch ex As Exception
MessageBox.Show(ex.Message)
Return Nothing
End Try
End Function
|
|
|
|