|
Ah, it might help if I read the documentation again, wouldn't it!
|
|
|
|
|
It always helps!
For instance, I hadn't realized that the IF operator also has a two-argument version which is the equivalent of the null-coalescing operator (?? ).
But then, since I don't use VB.NET, it doesn't really affect me.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
So I'm good to go Richard?
I'm using 4.0
|
|
|
|
|
|
Yes, your converted code is correct.
Depending on what the code is doing, you might want to look at the UriBuilder class[^].
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
It's for my ckEditor file browser program, sort of a plugin, in which I have to calculate the physical path of the image file and the virtual path, and pass it back to ckEditor.
This is the last part of the original vision for my eCommerce software that I started 6 years ago in vb or asp.net. It's almost done, been working on it for over 200 hours.So with this program, you can build a template in your web browser, save it as a job, and book the job and email it out to your mailing list, using the web service that I built.
I'll look at the URI article today, and see if I can use some of the knowledge from it.
Thanks for listening, and helping me out. I really appreciate it.
'Get the Domain name of the website
Dim m_urlPrefix As String = String.Format(
"{0}://{1}{2}{3}",
m_Context.Request.Url.Scheme,
m_Context.Request.Url.Host,
If(m_Context.Request.Url.Port = 80, String.Empty, ":" & m_Context.Request.Url.Port),
m_Context.Request.ApplicationPath
)
|
|
|
|
|
You could replace that code block with:
Dim m_urlPrefix As String = New Uri(m_Context.Request.Url, m_Context.Request.ApplicationPath).ToString()
That will return the same value for HTTP requests, and fix the minor bug with HTTPS requests, which use 443 as the default port.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I haven't done the 443 check yet, in which it will run in production mode on 443.
OK, I think I'll take your work on it.
|
|
|
|
|
Oh, Wait!
The final url is for a email campaign, in a port 80 environment. So regular people will be viewing the final url of the image, and wont be 443. Mail browsers and Outlook type programs will be using the URL.
|
|
|
|
|
Please I have DatagridView bound to a DataTable that pulls records and displays the DataGridView correctly. Now, I have ColumnType as DataGridViewComboBoxColumn of the forth column named "Username". When I click the combo box of the DataGridview, nothing gets displayed at all. I just don't understand it. Below is the code.
<pre lang="vb">
'Objects already initialized
Dim QueryU As String = "select * from Users where username='" & frmUsers.txtUsername.Text & "'"
Dim daUser As New SqlDataAdapter(QueryU, SQLCon)
Dim dtUser As New DataTable
daUser.Fill(dtUser)
If dtUser.Rows.Count > 0 Then
Dim c4 As New DataGridViewComboBoxColumn()
c4.HeaderText = "Send To"
c4.Name = "Username"
c4.DataPropertyName = "Username"
c4.DisplayMember = "Username"
c4.ValueMember = "Username"
c4.DisplayStyleForCurrentCellOnly = False
c4.DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing
c4.FlatStyle = FlatStyle.Popup
c4.SortMode = DataGridViewColumnSortMode.Automatic
c4.DataSource = dtUser
c4.Width = 300
frmUsers.DataGridView1.Columns.Add(c4)
Catch
End Try
End If
</pre>
|
|
|
|
|
Benniiit wrote: Dim QueryU As String = "select * from Users where username='" & frmUsers.txtUsername.Text & "'"
Your code is vulnerable to SQL Injection[^].
NEVER use string concatenation to build a SQL query. ALWAYS use a parameterized query.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
How can I show FileToUpload text box (server) if listItem is selected
<asp:RadioButtonList runat="server" ID="rbAction" RepeatDirection="Horizontal">
<asp:ListItem Text="Download" Value="Download"></asp:ListItem>
<asp:ListItem Text="Upload" Value="Upload"></asp:ListItem>
</asp:RadioButtonList>
<div style="position: relative; top: -2em; left: 2em;">
Select file for upload:
<asp:FileUpload ID="FileToUpload" runat="server" Width="500px" />
</div>
|
|
|
|
|
Hi,
In my a competition program I have a class with points.
There a multiple ways to sort. I want to know what systems you follow to sort.
different points
1. the game points.
2. the sum of the point from the oponents
3. the sum of the games that the player won
4. the individual game against a player.
How do you sort.
* create a routine for each system/compination
* combine all sort routines in 1 routine
* make some kind of formula and sort on that
* ...
thx
|
|
|
|
|
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.
|
|
|
|
|