|
Use LINQ[^].
The basic idea is that you have a single routine to sort a sequence, and separate out the logic for comparing two items in the sequence. The comparison can be achieved either by extracting a key from each item, providing a custom implementation of the IComparer(Of T) interface[^], or both.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
|
I'd stick with the "one method" approach or rather one interface. There is an article here on CP that introduces you to the usage of IComparable and IComparer . For the sake of flexibility I'd say you use the IComparer method. "Why is that?" you may ask. I'll try to explain.
Using the IComparable interface will make it hard to sort items on a flexible number of fields with both ascending and descding support for each field. The CompareTo method in the Icomparable interface only allows you to compare to another item of that type, but does not let you pass configuration information about the fields involved and the sort order (ascending/descending).
Using a dedicated IComparer class implementation remedies the above mentioned problems. The implementation of your special class that implements IComparer could be configured with the correct sequence in which to compare the fields and a factor of 1 or -1 for ascending or descending.
Here is how to proceed:
- Compare the fields in the sequence configured.
- You only need to compare another field if all fields previous in the sequence returned a comparison value of 0 (== they were all equal to another).
- Your
Compare(a, b) method should return the value of the first non-zero compare operation multiplied by the factor 1 for ascending or by -1 for descending, depending what has been configured for the field currently being compared. - If all fields compare as equal to each other return then 0. How this case is handled depends on whether the sorting algorithm is stable or not.
Regards,
Manfred
"I had the right to remain silent, but I didn't have the ability!"
Ron White, Comedian
|
|
|
|
|
thanks all
|
|
|
|
|
Nice that you got it sorted!
"I had the right to remain silent, but I didn't have the ability!"
Ron White, Comedian
|
|
|
|
|
I have a vbscript that creates automatically a incident in ServiceNow. Tested and it works.
But I wish to make it more practical and funcional. I am looking for a form based on this vbscript in order to create the incident.
Can you guys help me compiling a form based on the vbscript I am posting bellow? Many thanks.
Option Explicit
Const gServiceNowUser = "username"
Const gServiceNowPass = "password"
Const gServiceNowURL = "https://domain.service-now.com/"
Class ServiceNowDirectWS
' Use this class to call ServiceNow Direct Web Services functions
' For documentation on the Direct WS API see:
' http://wiki.servicenow.com/index.php?title=Direct_Web_Service_API_Functions
Dim sEndpointURL, sTableName, sMethod, sResponsePath
Dim oWSRequest, oWSRequestDoc, oWSResponseDoc
Dim oWSRequestEnvelope, oWSRequestBody, oWSRequestOperation
Public Sub SetMethod (tableName, method)
' This function must be called BEFORE Post to initialize the class
' method must be "insert", "update", "getKeys", "get" or "getRecords"
sTableName = tableName
sMethod = method
sResponsePath = "/soap:Envelope/soap:Body/" & sMethod & "Response/"
sEndpointURL = gServiceNowURL & sTableName & ".do?SOAP"
If (sMethod = "get" Or sMethod = "getRecords") Then
sEndpointURL = sEndpointURL & "&displayvalue=all"
End If
Set oWSRequest = CreateObject("MSXML2.XMLHTTP")
Set oWSRequestDoc = CreateObject("MSXML2.DOMDocument")
Set oWSRequestEnvelope = oWSRequestDoc.createElement("soap:Envelope")
oWSRequestEnvelope.setAttribute "xmlns:soap", _
"http://schemas.xmlsoap.org/soap/envelope/"
Set oWSRequestBody = oWSRequestDoc.createElement("soap:Body")
Set oWSRequestOperation = oWSRequestDoc.createElement("tns:" & sMethod)
oWSRequestOperation.setAttribute "xmlns:tns", _
"http://www.service-now.com/" & sTableName
oWSRequestDoc.appendChild oWSRequestEnvelope
oWSRequestEnvelope.appendChild oWSRequestBody
oWSRequestBody.appendChild oWSRequestOperation
End Sub
Public Function Post
' This function does the actual Web Services call
' It returns True if the call is successful and False if there is an error
oWSRequest.open "POST", sEndpointURL, False, gServiceNowUser, gServiceNowPass
oWSRequest.setRequestHeader "Content-Type", "text/xml"
oWSRequest.send oWSRequestDoc.xml
If oWSRequest.status = 200 Then
Set oWSResponseDoc = CreateObject("MSXML2.DOMDocument")
oWSResponseDoc.loadXML oWSRequest.responseText
oWSResponseDoc.setProperty "SelectionLanguage", "XPath"
oWSResponseDoc.setProperty "SelectionNamespaces", _
"xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'"
Post = True
Else
Set oWSResponseDoc = Nothing
Post = False
End if
End Function
Public Function Status
' If Post returns False then call this function to obtain the HTTP status code
Status = oWSRequest.status
End Function
Public Function StatusText
' If Post returns False then call this function for the error text
StatusText = oWSRequest.statusText
End Function
Public Sub SetValue(fieldname, fieldvalue)
' This function must be called BEFORE Post
Dim oChild
Set oChild = oWSRequestDoc.createElement(fieldname)
oChild.appendChild(oWSRequestDoc.createTextNode(fieldvalue))
oWSRequestOperation.appendChild(oChild)
End Sub
Public Function GetValue(fieldname)
' This function must be called AFTER Post
' If method is "insert" then it can be used to obtain the sys_id of the inserted record
' If method is "get" then it can be used to obtain any field from the record
GetValue = oWSResponseDoc.selectSingleNode(sResponsePath & fieldname).text
End Function
Public Function GetRowCount
' This function may be called after Post if the method is "getRecords"
' It returns the number of records in the result set
Dim sResultsPath, oNodeset
sResultsPath = sResponsePath & "getRecordsResult"
Set oNodeSet = oWSResponseDoc.selectNodes(sResultsPath)
getRowCount = oNodeSet.length
End Function
Public Function GetRowValue(rownum, fieldname)
' This function may be called after Post if the method is "getRecords"
' It returns a single field from a single record
Dim sRowPath, sFieldPath
sRowPath = sResponsePath & "getRecordsResult[" & rownum & "]/"
sFieldPath = sRowPath & fieldname
GetRowValue = oWSResponseDoc.selectSingleNode(sFieldPath).text
End Function
End Class
' Specify the ticket values
Dim wsInsertIncident : Set wsInsertIncident = New ServiceNowDirectWS
wsInsertIncident.SetMethod "incident", "insert"
wsInsertIncident.SetValue "short_description", "Incident Test"
wsInsertIncident.SetValue "description", "Incident Test"
wsInsertIncident.SetValue "caller_id", "My Username"
wsInsertIncident.SetValue "u_category", "Category Name"
wsInsertIncident.SetValue "u_subcategory", "Sub Category Name"
wsInsertIncident.SetValue "u_masiva", "Massive"
' Perform the insert and check the status
If Not wsInsertIncident.Post Then
WScript.Echo "Error=" & wsInsertIncident.Status
WScript.Echo wsInsertIncident.StatusText
WScript.Quit
End If
Dim strIncidentSysId, strIncidentNumber
strIncidentSysId = wsInsertIncident.GetValue("sys_id")
strIncidentNumber = wsInsertIncident.GetValue("number")
WScript.Echo "Inserted: " & strIncidentNumber
|
|
|
|
|
That depends on what you're using to make the form. VBScript doesn't have any in-built forms capability, so you're going to have to use an outside COM-based library to handle the forms for you or rewrite this into an HTA application.
An HTA app is basically a web page with VBScript code in it. Read this[^].
|
|
|
|
|
how to open password protected .pdf file in vb 6.0
|
|
|
|
|
By consulting the documentation on the viewer control you're using to show the PDF.
|
|
|
|
|
Hello !
I have a structure
Public Structure Mystruct
Property id as integer
Property name as string
Property value as integer
End Structure
......
Dim lst as List(of Mystruct)
I add several items in this list.
But how can I search in this list for example :
I want to search for an item that has .id=5 And .value<7 ? Is there a specific instruction or should I iterate through all the item with a for loop ?
Thank you !
|
|
|
|
|
dilkonika wrote: should I iterate through all the item with a for loop Yup. Or use LINQ, which also iterates the collection;
Module Module1
Public Structure Mystruct
Property id As Integer
Property name As String
Property value As Integer
End Structure
Dim lst As New List(Of Mystruct)
Sub Main()
lst.Add(New Mystruct() With {.id = 1, .name = "hello", .value = 2})
lst.Add(New Mystruct() With {.id = 5, .name = "test", .value = 5})
lst.Add(New Mystruct() With {.id = 5, .name = "world", .value = 9})
Dim lstFound As List(Of Mystruct) = lst.Where(Function(i As Mystruct) i.id = 5 AndAlso i.value < 7).ToList()
For Each item As Mystruct In lstFound
Console.WriteLine(item.name)
Next
Console.ReadKey()
End Sub
End Module
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Hi everybody
I have a trouble, that I don´t know how to solve. I´m trying to connect to database across internet, but my connection String don´t work.
I have use the same sintax that Connection String
http://www.connectionstrings.com/define-sql-server-network-protocol/[^]
I try to connect with Telnet and it´s working fine: Telnet 188.79.118.xxx 1433
This is my code
Dim Connection,Recordset,query,Reg
Set Connection = CreateObject("ADODB.Connection")
Set Recordset = CreateObject("ADODB.Recordset")
Connection.Open "Provider=SQLOLEDB; Data Source=188.79.118.xxx,1433\INST;Network Library=DBMSSOCN;Initial Catalog= DataBase ; User Id= sa; Password=xxxx"
query = "Select * From Alarmas"
Recordset.Open query,Connection,1,1
Reg = Recordset.RecordCount
msgbox Reg
Recordset.Close
Set Recordset=Nothing
Connection.Close
Set Connection=Nothing
This give me the following error
DBNETLIB ConnectionOpen (Invalid Connection())Conexion no valida
Codigo 80004005
Any suggestion will be gratefull.
Thanks Advanced.
|
|
|
|
|
Problem is that most providers do not allow direct access to the database from the internet.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Thank you very much for you reply
Do you have any suggestion?
|
|
|
|
|
There are some options;
Host your own - get a public IP, set up a PC and install a database-server. You'll be cursing a lot though, since there's a lot of strange folk out there trying to log in to anything they find.
Create webservices. The same providers often provide webspace and a server-side language; most often PHP, sometimes ASP.NET. Write a webservice to do a ExecuteNonQuery and ExecuteReader. (This would also allow for some authentication and protection of the database)
Go for a (paid) cloud.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Thank you so much for your suggestion.
|
|
|
|
|
Not much help, as it hardly solves your problem.
If you can then it prolly does pay to take the long route. Host your own server, host your own webservices (never give away database-access) and you essentially have a secure and private cloud.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Since you can telnet to that IP address and port, I'd rather think that the user 'sa' may not be configured for remote connections. Create a different user and try again.
And:
Data Source=188.79.118.xxx,1433\INST
ought to be changed to
Data Source=188.79.118.xxx:1433\INST
(i.e. the ',' replaced by a ':').
|
|
|
|
|
Thank you so much for your reply Bernhard.
I try with this settings, but still I can´t connect.
So, I have been talking with Mr. Eddy Vluggen and everything seem to be correctly. Then his suggestion was change default port 1433 to another, like 8080 - 8181, and righ now it´s working perfectly. If someone has the same problem, can try it.
Thank you very much both of you!!!
|
|
|
|
|
Hello !
I have this structure , and a list:
Public Structure tabinfo
Public tb As String
Public fld As String
Public name As String
Public tp As integer
End Structure
......
Dim lst as List(of tabinfo)
I try to fill the lst and after bind the Listbox to lst :
lst.Add(New tabinfo() With {.tb = "a", .fld = "nr", .name = "Number", .tp = 1})
listBox1.DataSource = lst
listBox1.DataTextField = "name"
listBox1.DataValueField = "fld"
listBox1.DataBind()
..But on runtime , I have 1 item in listbox , but is empty ( Since "name" is the display field i expect the string "Number" should be displayed ) .
What's wrong ?
Thank you !
|
|
|
|
|
I thought the display field is listbox1.DisplayField .
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Good day friends! I developed a simple program that write to and read from text file. I made the program become installable and installed it in my system. When I right clicked on a text file in my device local disk, and chosed open with, and selected my application exe, the program loads but the textbox was empty. Please, my request is, how can I add a functionality that will capture the textfile content and display it on the textbox when I used the open with command from the windows explorer? Please help. Thanks in advance!!!
|
|
|
|
|
Without seeing your code it's hard to help.
Are you parsing the command line properly and reading the file content?
|
|
|
|
|
VB6 is dead. It is no longer sold, supported nor maintained. No new code should be written in VB6.
VB.NET is available for FREE, has lots of examples on the most tasks that we're confronted with and has a huge userbase.
Once you have done that, I'll gladly help you in consuming the startup parameter. Your application (in whatever language) gets the path to the text-file as its first argument. Meaning you'd simply look into the command-line-arguments from your application.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Eddy Vluggen wrote: VB6 is dead. It is no longer sold, supported nor maintained. No new code should be written in VB6. Never! Never surrender!!
In all seriousness, Office still has VBA so it is very much still alive.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|