|
Ben Senior wrote: not much useful reference material Seriously? There is no end of it, from MSDN documentation to articles in both VB and C#.
|
|
|
|
|
I'd like to help you, but I'm a bit unclear as to what you need to do.
Do you want to take,
<descrip type="reliabilityCode">3</descrip>
and change it to
<descrip type="reliabilityCode">reliabilityCode</descrip>
and do the same for
<descrip type="subjectField">6411, 6821</descrip>
I think this can be done cleaner with xPath statements, rather then lots of looping.
If my understanding is correct, then I will help with the xPath statements.
![Java | [Coffee]](https://codeproject.global.ssl.fastly.net/script/Forums/Images/coffee.gif)
|
|
|
|
|
Hi David,
No. What I want to do is take:
<descrip type="reliabilityCode">3
and replace it with:
<descrip type="reliabilityCode">Very reliable
The "3" can vary and when I get this numerical code I have a function from where I can retrieve its text equivalent. I then need to insert the text equivalent back into the XML file. There are five of these numeric codes.
I'm new to XML and have never used XPath before so I'm struggling at the moment. I've been researching XPath and LINQ and just can't seem to get the hang of them.
I have been using the looping as that's what I'm used to doing in VB and C#.
The last thing that I will need to do is go through each element and depending upon the value of the subject field write the whole element to a new file for that subject. But first thing first and replace the numeric codes with text.
The subjectField is very similar other than there are over 700 subjects. I already have a function which converts the numeric subject field codes into text, and as above I need to insert the text back into the XML file.
|
|
|
|
|
See if this code helps. I realize that it doesn't do exactly what you want, but it shows how xPath works.
Dim xDoc As New XmlDocument
Dim xNodeList As XmlNodeList
Dim xNode As XmlNode
xDoc.Load("C:\Temp\test.xml")
xNodeList = xDoc.SelectNodes("/conceptGrp/descripGrp/descrip[@type='subjectField']")
For Each xNode In xNodeList
xNode.InnerText = xNode.Attributes("type").Value
Debug.Print(xNode.InnerText)
Next
xDoc.Save("C:\Temp\test_1.xml")
|
|
|
|
|
I had to add the root to the code ie. "/mtf/conceptGrp/descripGrp/descrip[@type='subjectField']" and a variable codeID to hold the value from
codeID = xNode.InnerText instead of your
xNode.InnerText
I replaced the codeID with codeText (the corresponding text from my function) and reinserted it into the xml file.
I need to test out the subjectField, but I don't anticipate any difficulties because it basically the same as for reliabilityCode.
Works a treat. Thanks for your help. Now I'm getting there with XPath 
|
|
|
|
|
You can get and set the value using LINQ to XML and XML axis properties.
Dim conceptor = XDocument.Load("C:\file.xml")
Dim subjectField = conceptor...<descrip>.Where(Function(d) d.@type = "subjectField").Value
conceptor...<descrip>.Where(Function(d) d.@type = "subjectField").Value = "1234"
conceptor.Save("C:\file.xml")
The descendant axis property, ...<> , gets all descendants that have the name specified within the angle brackets. The attribute axis property, .@ , returns a reference to the value of the specified attribute. The Value axis property returns a reference to the value of the first element in a collection of elements.
"As beings of finite lifespan, our contributions to the sum of human knowledge is one of the greatest endeavors we can undertake and one of the defining characteristics of humanity itself"
|
|
|
|
|
Thanks for that Meschack,
As I said above I have solved that problem, with the help of people here, and now moved on to the next stage in the project, which is moving along quite well.
I have noted your suggestions along with the others, for reference and future use.
|
|
|
|
|
I have been handed an assignment: update a legacy "window" application. The UI must work the same to avoid user re-training costs. The source code is lost/unavailable. (I suspect it was written by a consultant who did not leave the source code. ) This legacy code will not run on Win7 or Win10. (Now you see why it must be updated immediately.. )
My problem is that the original author "caught" the Shift, Control and Alt keys to select which data frame to display. If none of the three are pressed and held, the most common data is displayed. If the Shift key is pressed and held, the demographics data is displayed. You get the picture. None of these data frames have any interactive controls. The KeyUp, KeyPress, and KeyDown events are not being caught when these keys are pressed:
Private Sub ucDisplay_KeyUp(sender As Object, _
e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyUp
Stop
End Sub
Any suggestions on how to catch these events? Can someone point me to a useful reference?
Thank you.
__________________
Lord, grant me the serenity to accept that there are some things I just can’t keep up with, the determination to keep up with the things I must keep up with, and the wisdom to find a good RSS feed from someone who keeps up with what I’d like to, but just don’t have the damn bandwidth to handle right now.
© 2009, Rex Hammock
|
|
|
|
|
Private Shiftdown As Boolean = False
Private altdown As Boolean = False
Private cntrldown As Boolean = False
Private Sub ucDisplay_KeyUp(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyUp
Select Case e.KeyCode
Case Keys.ShiftKey
Shiftdown = False
Case Keys.Menu
altdown = False
Case Keys.ControlKey
cntrldown = False
End Select
End Sub
Private Sub ucDisplay_Keydown(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
Select Case e.KeyCode
Case Keys.ShiftKey
Shiftdown = True
Case Keys.Menu
altdown = True
Case Keys.ControlKey
cntrldown = True
End Select
If Shiftdown AndAlso altdown AndAlso cntrldown Then
End If
End Sub
modified 17-May-17 5:24am.
|
|
|
|
|
The KeyUp event only fires when the key is released. It sounds like you want to handle the KeyDown event instead.
Jalapeno Bob wrote: The source code is lost/unavailable.
Is it a .NET application? If so, and if the consultant didn't use an obfuscator, you might be able to use a decompiler to see what the code is doing. It won't give you a perfect copy of the original source, but it might help.
Free .NET decompiler :: JetBrains dotPeek[^]
JustDecompile .NET Assembly Decompiler & Browser - Telerik[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Great Idea!!! Except: Visual Studio shows Intel 80x86 assembly language, not CLR Intermediate language. No symbol table. Just one .exe file. Last compiled in 2001, probably for Win98. Like I said "Legacy code"
__________________
Lord, grant me the serenity to accept that there are some things I just can’t keep up with, the determination to keep up with the things I must keep up with, and the wisdom to find a good RSS feed from someone who keeps up with what I’d like to, but just don’t have the damn bandwidth to handle right now.
© 2009, Rex Hammock
|
|
|
|
|
GOOD DAY FRIENDS! Please, is it possible to detect when the pc or laptop position changes using visual basic? Take for instance, if pc was initially located at position A and later moved to position B; then, the application should be able to get the position's changes.
In a simplified term, assuming pc was in Lat. 30 and Log. 40, if position changes, then the lat. and log. values should also change.
Finally found what I want but it is in javascript.
Can anyone convert this to a desktop application in vb.
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
window.onload = function () {
var mapOptions = {
center: new google.maps.LatLng(18.9300, 72.8200),
zoom: 14,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var infoWindow = new google.maps.InfoWindow();
var latlngbounds = new google.maps.LatLngBounds();
var map = new google.maps.Map(document.getElementById("dvMap"), mapOptions);
google.maps.event.addListener(map, 'click', function (e) {
alert("Latitude: " + e.latLng.lat() + "\r\nLongitude: " + e.latLng.lng());
});
}
</script>
<div id="dvMap" style="width: 500px; height: 500px">
</div>
</body>
</html>
Thanks in advance!
modified 12-May-17 15:12pm.
|
|
|
|
|
If the machine has inbuilt GPS hardware then yes, probably. If not, you may be able to get a rough location from wifi connection data. Accuracy will be poor though.
=========================================================
I'm an optoholic - my glass is always half full of vodka.
=========================================================
|
|
|
|
|
Thanks for your response. How can I achieve this your suggestion please?
|
|
|
|
|
Investigate the Google Maps API
=========================================================
I'm an optoholic - my glass is always half full of vodka.
=========================================================
|
|
|
|
|
Thank you so much for your time of response. Please, I tried reading about google's map api but not getting the flow. It only shows the country as a whole. But what am looking for is, assuming a pc position was lat 30.001 and log. 40.687 and was later shifted from initial position to another. I want the software to update it self with the pc current position. Please help. Once again, thanks.
modified 4-Jul-17 1:26am.
|
|
|
|
|
And how is that software supposed to know when the PC has been moved, or to figure out exactly where it is on the surface of the earth? As has already been mentioned, unless the PC contains a GPS receiver then you cannot do it.
|
|
|
|
|
The script posted by me connects to Google Map API and retrieves someone current lat. and log. but it is written in JavaScript.Looking for a way to convert it to VB (VB 6.0 or VB.Net). Any help please.
|
|
|
|
|
OK, but Google Maps API does't magically know with any REAL accuracy where the machine is UNLESS IT HAS A GPS RECEIVER. Without that YOU have to tell Google where the machine is. If you rely on any other detection machanism, like Geomapping an IP, it can be off by dozens of miles. Right now, if I don't tell Google explicitly, it'll guess that my machine is 36 miles from where it really is.
|
|
|
|
|
Thanks for your vital information!
|
|
|
|
|
How many times do we need to explain: if you do not have a GPS receiver in the PC no software can find its location. Google maps will only tell you the location of the IP address of your broadband provider. In my case that is some 70 miles from where I live.
|
|
|
|
|
There are many ways that you can do this, first and foremost has been shared with you through the use of GPS hardware. That will detect the location, and you can then write the program to get the location and show it or process it.
However, if you need to get the location of a machine inside the office or a building, you can also possibly use the network interfaces, to determine where the machine is at the moment. Note that, this is very bad in cases where you need to pinpoint location, but changes can be detected easily based on the network or the endpoint from where the machine is communication.
And as for Visual Basic, which one? The VB 6? I am unsure, whether you will be able find any solution for that, C++ or C# or Java might do some help in these cases. Even Vb.NET would require some help from C# world.
Have a look here, monitoring - Is it possible to find a computer's physical location in a room? - Server Fault
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
Thanks for your vital information!
|
|
|
|
|
Here is my code, I am trying to return EmpDetails.
Structure Employee
Dim EName As String
Dim ESalary As String
End Structure
Dim EmpDetails() As Employee
Function EMPInfo(ByVal names As String()) As String()
Dim i AS Integer
Select Case nameses(i)
Case "ABC"
EmpDetails(i - 1)EName = "Dave"
EmpDetails(i - 1).ESalary = "30,000"
Case "SPE"
EmpDetails(i - 1).EName = "Eva"
EmpDetails(i - 1).ESalary = "40,000"
Case "P,SIGM"
EmpDetails(i - 1).EName = "Steve"
EmpDetails(i - 1).ESalary = "70,000"
End Select
Next
Return EmpDetails
I am getting the error for the return EmpDetails
Error: Value of type '1-dimensional array cannot be converted to '1-dimensional array of String'
What I am doing wrong in here.
Thanks in advance.
|
|
|
|
|
Shouldn't the function return Employee() ?
Try it.
|
|
|
|