 |
 |
Apologies for the shouting but this is important.
When answering a question please:
- Read the question carefully
- Understand that English isn't everyone's first language so be lenient of bad spelling and grammar
- If a question is poorly phrased then either ask for clarification, ignore it, or mark it down. Insults are not welcome
- If the question is inappropriate then click the 'vote to remove message' button
Insults, slap-downs and sarcasm aren't welcome. Let's work to help developers, not make them feel stupid.
cheers,
Chris Maunder
The Code Project Co-founder
Microsoft C++ MVP
|
|
|
|
 |
For those new to message boards please try to follow a few simple rules when posting your question.- Choose the correct forum for your message. Posting a VB.NET question in the C++ forum will end in tears.
- Be specific! Don't ask "can someone send me the code to create an application that does 'X'. Pinpoint exactly what it is you need help with.
- Keep the subject line brief, but descriptive. eg "File Serialization problem"
- Keep the question as brief as possible. If you have to include code, include the smallest snippet of code you can.
- Be careful when including code that you haven't made a typo. Typing mistakes can become the focal point instead of the actual question you asked.
- Do not remove or empty a message if others have replied. Keep the thread intact and available for others to search and read. If your problem was answered then edit your message and add "[Solved]" to the subject line of the original post, and cast an approval vote to the one or several answers that really helped you.
- If you are posting source code with your question, place it inside <pre></pre> tags. We advise you also check the "Encode "<" (and other HTML) characters when pasting" checkbox before pasting anything inside the PRE block, and make sure "Use HTML in this post" check box is checked.
- Be courteous and DON'T SHOUT. Everyone here helps because they enjoy helping others, not because it's their job.
- Please do not post links to your question into an unrelated forum such as the lounge. It will be deleted. Likewise, do not post the same question in more than one forum.
- Do not be abusive, offensive, inappropriate or harass anyone on the boards. Doing so will get you kicked off and banned. Play nice.
- If you have a school or university assignment, assume that your teacher or lecturer is also reading these forums.
- No advertising or soliciting.
- We reserve the right to move your posts to a more appropriate forum or to delete anything deemed inappropriate or illegal.
cheers,
Chris Maunder
The Code Project Co-founder
Microsoft C++ MVP
|
|
|
|
 |
I never did get any good or practice these in the past, I can't even remember what there called
But I know it's a if then else statement.
Just wondering if someone could translate this for me to vb, or help me with the keywords to look up a tutorial on this.
context.Request.Url.Port == 80 ? string.Empty : ":" + context.Request.Url.Port
|
|
|
|
 |
I think I got it, it may be a tenary Operator
If(m_Context.Request.Url.Port = 80, String.Empty, ":" & m_Context.Request.Url.Port)
|
|
|
|
 |
Keep in mind that there is no direct replacement in VB.NET for C#'s ternary operator.
What you have may work, but there is a problem. Since IF() and IIF() are both methods, ALL arguments being passed to them are evaluated. This is not true in the C# operator.
For example, if you have C# code that reads:
string value = someObject.someProp == 0 ? myObject.prop + "something" : otherObject.prop
What if myObject is null when someObject.someProp does not equal 0? In C#, this wouldn't be a problem because the first return value (between the ? and colon) does not get evaluated when the statement is executed.
In the VB.NET version of the code:
Dim value As String = If(someObject.someProp = 0, myObject.prop + "something", otherObject.prop)
will throw an exception because you can't return the prop property on a Nothing object (myObject).
|
|
|
|
 |
Dave Kreskowiak wrote: Since IF() and IIF() are both methods, ALL arguments being passed to them are evaluated.
Not true - the IF operator[^], added in .NET 3.5, is directly equivalent to the C# ternary operator.
Your comment is true for the old IIF function[^], but that's not what the OP is using.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
 |
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.
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
|
|
|
|
 |
|