Extract text from <example>TEXT</example> (1 Viewer)

FreshCoder

Registered User.
Local time
Today, 12:54
Joined
Sep 22, 2018
Messages
33
Hi!
I need help with some code. Im making a medical record and need to extract what`s between <example>TEXT</example> and put it in text boxes.


Code:
Option Compare Database
Option Explicit

Private Sub txtJournal_AfterUpdate()

Dim i As String
Dim txtJournal As String

For i = 1 To Len(txtJournal)

If Mid(txtJournal, i, 1) = "<diagnose>" Then
ElseIf Mid(txtJournal, i, 1) = "</diagnose>" Then

Next i

If Mid(txtJournal, i, 1) = "<resept>" Then
ElseIf Mid(txtJournal, i, 1) = "</resept>" Then


End If
End Sub
 

Attachments

  • patient.PNG
    patient.PNG
    10.3 KB · Views: 218

Gasman

Enthusiastic Amateur
Local time
Today, 20:54
Joined
Sep 21, 2011
Messages
14,296
I'd probably write a function and then pass the tag I am looking for and return what is between the start and end html tags.

That is assuming the tags are not repeated.? ie one diagnose and one resept. ?
 

JHB

Have been here a while
Local time
Today, 21:54
Joined
Jun 17, 2012
Messages
7,732
Attache is a sample database, change something in the Journal control and hit <Return>
 

Attachments

  • TheSplit.accdb
    360 KB · Views: 306

FreshCoder

Registered User.
Local time
Today, 12:54
Joined
Sep 22, 2018
Messages
33
I'd probably write a function and then pass the tag I am looking for and return what is between the start and end html tags.

That is assuming the tags are not repeated.? ie one diagnose and one resept. ?


Its not repeated!
 

isladogs

MVP / VIP
Local time
Today, 20:54
Joined
Jan 14, 2017
Messages
18,219
Here's a variation using a function GetBetween rather than the Split function
 

Attachments

  • FreshCoder.zip
    25 KB · Views: 315

FreshCoder

Registered User.
Local time
Today, 12:54
Joined
Sep 22, 2018
Messages
33
Thank you very much for writing those programs! Exactly what i was looking for :D:) Gonna look into them and try to learn something :)
 

isladogs

MVP / VIP
Local time
Today, 20:54
Joined
Jan 14, 2017
Messages
18,219
Excellent. Both solutions work. Choose whichever you prefer.
 

FreshCoder

Registered User.
Local time
Today, 12:54
Joined
Sep 22, 2018
Messages
33
What do i need to do with this code if i want to add more <diagnose> and <resept>?



Code:
Option Compare Database
Option Explicit

Private Sub txtJournal_AfterUpdate()
  Dim strSplit() As String
  
  strSplit = Split(Me.txtJournal, "<diagnose>")
  If UBound(strSplit) > 0 Then
    strSplit = Split(strSplit(1), "</diagnose>")
    If UBound(strSplit) > 0 Then
      Me.diagnose = strSplit(0)
    Else
      MsgBox ("End of diagnose not found!")
    End If
  Else
    MsgBox ("Start of diagnose not found!")
  End If
  strSplit = Split(Me.txtJournal, "<resept>")
  If UBound(strSplit) > 0 Then
    strSplit = Split(strSplit(1), "</resept>")
    If UBound(strSplit) > 0 Then
      Me.Resept = strSplit(0)
    Else
      MsgBox ("End of resept not found!")
    End If
  Else
    MsgBox ("Start of resept not found!")
  End If
End Sub
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 15:54
Joined
May 21, 2018
Messages
8,527
if i want to add more <diagnose> and <resept>?
I assume that means multiple occurrences of those two tags. I so, what would you like to do with this. Give an example of the input and what you would like for an output.
 

FreshCoder

Registered User.
Local time
Today, 12:54
Joined
Sep 22, 2018
Messages
33
I uploaded a image of what i mean. And the program it self.
 

Attachments

  • patient.PNG
    patient.PNG
    8.5 KB · Views: 307
  • TheSplit.accdb
    360 KB · Views: 294

isladogs

MVP / VIP
Local time
Today, 20:54
Joined
Jan 14, 2017
Messages
18,219
Earlier you stated each item would not be repeated. Has that now changed?

How do you want the output displayed? Each diagnosis on a new line? Similarly for resept?

Do you only want the solution using Split or would the GetBetween solution also be OK?
 
Last edited:

FreshCoder

Registered User.
Local time
Today, 12:54
Joined
Sep 22, 2018
Messages
33
If you could do it for both Split and GetBetween it would be great! But i will only need one for school.
I want the next diagnose to be displayed in a new line below. similar for resept.
 

Gasman

Enthusiastic Amateur
Local time
Today, 20:54
Joined
Sep 21, 2011
Messages
14,296
If you could do it for both Split and GetBetween it would be great! But i will only need one for school.
I want the next diagnose to be displayed in a new line below. similar for resept.

Surely each diagnosis would be on certain date? Whilst there might be multiple symptoms, they would be all confined within a diagnosis for that visit.?

So one diagnosis and response per record?
 

isladogs

MVP / VIP
Local time
Today, 20:54
Joined
Jan 14, 2017
Messages
18,219
So this is a school project?
You should have said so from the start as well as follow guidelines regarding cross posting.

Before going any further you need to sort out table design.
Agree with Gasman that each diagnosis would normally be a separate record which makes the extra work redundant
Will you just display the diagnose and respect values or want to save them as separate fields (thus duplicating data).

Think it all through properly and come back again with your table design and several examples

No, I won't do both methods.
I may do GetBetween (if it's necessary) but someone else can deal with Split.
 

JHB

Have been here a while
Local time
Today, 21:54
Joined
Jun 17, 2012
Messages
7,732
Yes, you should have mentioned that it was a school project.
To me, it is very different if I help one with an IRL problem or one to prove how clever he is in programming.
Remember it's you to judge how smart you are, and not how clever we are.
I think you have got 2 good solutions that you should try to work on alone to see if you can solve your other problem.
If you gets any problems, you can always post your code here and we can assist you further, but at the moment you have to go to the track and show what you able to produce.
A hint: In the solution with the split function, you should use 2 arrays.
 

FreshCoder

Registered User.
Local time
Today, 12:54
Joined
Sep 22, 2018
Messages
33
Yes it is a school project. And sorry guys!


Ive tried to make room for more diagnose and resept in the split version but the problem is that it overwrites the last diagnose/resept. I need it to fill in below. Like a vertical list. I would rather use <diagnose> for the next diagnose, but i tried with <diagnose2> and vbNewLine for next diagnose.
I dont need dates for this one. And sorry for my english.



Code:
Option Compare Database
Option Explicit

Private Sub txtJournal_AfterUpdate()
  Dim strSplit() As String
  
  strSplit = Split(Me.txtJournal, "<diagnose>")
  If UBound(strSplit) > 0 Then
    strSplit = Split(strSplit(1), "</diagnose>")
    If UBound(strSplit) > 0 Then
      Me.diagnose = strSplit(0) & vbNewLine
    Else
      MsgBox ("End of diagnose not found!")
    End If
    MsgBox ("Start of diagnose not found!")
  End If

  strSplit = Split(Me.txtJournal, "<diagnose2>")
  If UBound(strSplit) > 0 Then
    strSplit = Split(strSplit(1), "</diagnose2>")
    If UBound(strSplit) > 0 Then
      Me.diagnose = strSplit(0)

  strSplit = Split(Me.txtJournal, "<resept>")
  If UBound(strSplit) > 0 Then
    strSplit = Split(strSplit(1), "</resept>")
    If UBound(strSplit) > 0 Then
      Me.Resept = strSplit(0)
        Else
      MsgBox ("End of resept not found!")
    End If
  Else
    MsgBox ("Start of resept not found!")
  End If
    Else
      MsgBox ("End of diagnose not found!")
    End If
    MsgBox ("Start of diagnose not found!")
  End If
  
  End Sub
 

Attachments

  • Split-Problem.PNG
    Split-Problem.PNG
    7 KB · Views: 295

Gasman

Enthusiastic Amateur
Local time
Today, 20:54
Joined
Sep 21, 2011
Messages
14,296
Think about it.
You have the first diagnose and need to add the second?
So the code for the second would be something like
Code:
Me.diagnose = Me.Diagnose & vbCRLF & strSplit(0)

However what happens if you have 3 or 4 or more?

HTH
 

FreshCoder

Registered User.
Local time
Today, 12:54
Joined
Sep 22, 2018
Messages
33
Yes. The idea was to allow fore more <diagnose> and <resept>, but i couldnt find the way to do it. I will need to make <diagnose2>-3-4 and so on. But im guessing this is doing it way to hard.
Trying your solution for new line now
 

Attachments

  • TheSplit – Several.accdb
    544 KB · Views: 292

Users who are viewing this thread

Top Bottom