Show the particular component of the screen when backed - codenameone

I've a screen with a list of components. When I scroll down the screen, go to the next screen from a button (lets say 20th component) and go back to the previous screen with back btn, the previous screen (with list of components) displays with the first component there. How can I show the screen with 20th component when backed?
Look at the video here
Container mainContainer = new Container(new BoxLayout(BoxLayout.Y_AXIS));
mainContainer.setScrollableY(true);
for (Map<String, Object> entrySet : protectedPlantsList) {
String title = entrySet.get("title").toString();
String sname = entrySet.get("sname").toString();
String nname = entrySet.get("nname").toString();
Label plantSpeciesLabel = new Label(title);
TextArea family = new TextArea(sname);
TextArea nepaliName = new TextArea(nname);
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
Button infoIcon1 = new Button("", "TextField");
infoIcon1.addActionListener(e -> {
new ThreatCategory(res, threatData1.getName(), infoIcon1.getName(), threatList).show();
});
mainContainer.add(BorderLayout.centerEastWest(plantSpeciesLabel, ...., .....));
}
Update 1:
ProtectedPlantAndSpecies class:
Container mainContainer = new Container(new BoxLayout(BoxLayout.Y_AXIS));
mainContainer.setScrollableY(true);
for (Map<String, Object> entrySet : protectedPlantsList) {
String title = entrySet.get("title").toString();
String sname = entrySet.get("sname").toString();
String nname = entrySet.get("nname").toString();
Label plantSpeciesLabel = new Label(title);
TextArea family = new TextArea(sname);
TextArea nepaliName = new TextArea(nname);
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
Button infoIcon1 = new Button("", "TextField");
infoIcon1.addActionListener(e -> {
Form myDestinationForm = new ThreatCategory(res, cat, cat_description, threatList);
myDestinationForm.addShowListener(f -> infoIcon1.requestFocus());
myDestinationForm.show();
});
mainContainer.add(BorderLayout.centerEastWest(plantSpeciesLabel, ...., .....));
}
ThreatCategory class:
- - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - -
Command backCommand = new Command("Back", backFontImage) {
#Override
public void actionPerformed(ActionEvent evt) {
new ProtectedPlantAndSpecies(res, true).show();
}
};
- - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - -

Do something like this:
Form hi = new Form("Last", BoxLayout.y());
Button t = new Button("Next");
hi.add(t);
t.addActionListener(e -> {
Form f = new Form("Showing Last", BoxLayout.y());
for(int iter = 0 ; iter < 20 ; iter++) {
f.add(new Button("Button " + iter));
}
Button last = new Button("Last");
f.add(last);
f.addShowListener(ee -> last.requestFocus());
f.show();
});

Related

Putting a new item in to the calendar overwrites the other item inside

Hello can someone please tell me what could be the problem in my calendar. So let me explain whats happening. So first im trying to make a scheduler application and im using a WPF scheduler in VB, so to begin with, the tab of a calendar needs to display 3 items (Subject, Professor Name, Courses) so what i need to do is to choose a room first and then drag a subject name from the listbox (like this Sample1) and then next i need to drag a professors name (Sample2) and then heres where the problems starts
So it already displays two items (Subject and Professor) now i need to drag an item from Course listbox, but the problem is whenever I put a course to the tab of a calendar, it becomes like this instead
So the goal here is to show 3 dragged items but instead, it only shows 2 and the course is overwriting the name of the subject. Please help me, thank you! If you want to see the whole codes, heres the link https://drive.google.com/file/d/1fWKisPr9qDh54B4EMdwWJbY3KFgi_xfc/view?usp=sharing
Heres the code of where you can drag the items
'Dragging Data to Calendar
Sub Add_list_item(ByVal list As String)
Delay.Delay(1)
Dim count = 0
For Each item As CalendarItem In Calendar1.GetSelectedItems()
count += 1
If count > 1 Then
Return
Else
Dim get_item_end_time As DateTime = item.EndDate.AddHours(2)
get_item_end_time = get_item_end_time.AddMinutes(30)
Dim item_start_time = item.StartDate
Dim item_end_time = get_item_end_time
Dim item_tooltip = item.StartDate.ToString()
Dim start_time = item.StartDate.ToString("HH:mm tt")
Dim end_time = item.EndDate.ToString("HH:mm tt")
Dim dat_start As Date = item_tooltip
Dim ci As CultureInfo = CultureInfo.CreateSpecificCulture("en-US")
Dim dtfi As DateTimeFormatInfo = ci.DateTimeFormat
dtfi.AbbreviatedDayNames = {"Sun", "1", "2", "3", "4",
"5", "6"}
Dim output_start As String = String.Format(ci, "{0:ddd}", dat_start.AddDays(0))
Dim item_text = CStr(item.Text)
Dim parts As String() = item_text.Split(New String() {Environment.NewLine},
StringSplitOptions.None)
Dim get_item_total_hours = (item.EndDate - item.StartDate).TotalHours
Dim get_start_time As DateTime
Dim get_end_time As DateTime
If get_item_total_hours = 1 Then
get_start_time = item.StartDate.AddMinutes(-30)
get_end_time = item.EndDate.AddMinutes(30)
ElseIf get_item_total_hours = 1.5 Then
get_start_time = item.StartDate.AddHours(-1)
get_end_time = item.EndDate.AddHours(1)
ElseIf get_item_total_hours = 2 Then
get_start_time = item.StartDate.AddHours(-1).AddMinutes(-30)
get_end_time = item.EndDate.AddHours(1).AddMinutes(30)
ElseIf get_item_total_hours = 2.5 Then
get_start_time = item.StartDate.AddHours(-2)
get_end_time = item.EndDate.AddHours(2)
ElseIf get_item_total_hours = 3 Then
get_start_time = item.StartDate.AddHours(-2).AddMinutes(-30)
get_end_time = item.EndDate.AddHours(2).AddMinutes(30)
ElseIf get_item_total_hours = 3.5 Then
get_start_time = item.StartDate.AddHours(-3)
get_end_time = item.EndDate.AddHours(3)
ElseIf get_item_total_hours = 4 Then
get_start_time = item.StartDate.AddHours(-3).AddMinutes(-30)
get_end_time = item.EndDate.AddHours(3).AddMinutes(30)
ElseIf get_item_total_hours = 4.5 Then
get_start_time = item.StartDate.AddHours(-4)
get_end_time = item.EndDate.AddHours(4)
ElseIf get_item_total_hours = 5 Then
get_start_time = item.StartDate.AddHours(-4).AddMinutes(-30)
get_end_time = item.EndDate.AddHours(4).AddMinutes(30)
ElseIf get_item_total_hours = 5.5 Then
get_start_time = item.StartDate.AddHours(-5)
get_end_time = item.EndDate.AddHours(5)
ElseIf get_item_total_hours = 6 Then
get_start_time = item.StartDate.AddHours(-5).AddMinutes(-30)
get_end_time = item.EndDate.AddHours(5).AddMinutes(30)
End If
If (ListBox1_Instructor.Items.Contains(list) = True) Then
Call Check_if_instructor(list)
End If
If parts.Count >= 3 Then
If (instructor_name = True) Then
Call Get_instructor_code(instructor_gender + list)
Call Get_course_name(corSec_id)
Call checkInstructorSchedule(start_time, end_time, output_start, instructor_id)
If (instructor_name = True) Then
If instructor_gender = "Male" Then
instructor_gender = "Mr. "
Else
instructor_gender = "Ms. "
End If
If item.Text <> "" Then
item.Text = parts(0) + vbNewLine + vbNewLine + instructor_gender + list
item.ApplyColor(Color.RoyalBlue)
End If
instructor_name = False
End If
Else
item.ApplyColor(Color.RoyalBlue)
item.Text = list + vbNewLine + vbNewLine + parts(2) + vbNewLine + vbNewLine
End If
ElseIf parts.Count = 1 Then
If (instructor_name = True) Then
Call Get_instructor_code(instructor_gender + list)
Call Get_course_name(corSec_id)
Call checkInstructorSchedule(start_time, end_time, output_start, instructor_id)
If (instructor_name = True) Then
If instructor_gender = "Male" Then
instructor_gender = "Mr. "
Else
instructor_gender = "Ms. "
End If
If item.Text <> "" Then
item.Text = parts(0) + vbNewLine + vbNewLine + instructor_gender + list
item.ApplyColor(Color.RoyalBlue)
End If
instructor_name = False
End If
Else
item.ApplyColor(Color.RoyalBlue)
item.Text = list + vbNewLine + vbNewLine + parts(parts.Count - 1) + vbNewLine + vbNewLine
End If
End If
Calendar1.Invalidate(item)
End If
Next
End Sub

Macro not working when the file is unshared and share again

I'm trying to add a couple of simple macros to a file that is a shared excel binary workbook. The problem whenever the file is unshared the macro does not work anymore. The code is as following:
Sub uploadMain()
Dim xlsFile As String
Dim wbResults As Workbook
Dim wbmCall As Workbook
Dim agmtCdCell As Range
Dim amtCldCell As Range
Dim srchRange As Integer
Dim callClmn As Integer
Dim srchString As String
Dim callAmt As String
Dim notFound As String
Dim lastRowNo As Long
Dim srchRowNo As Long
Dim srcRowNo As Long
Dim customView As Boolean
Dim amntReplaced As Boolean
Dim asset_column As Integer
Dim typ
Dim quantity_column As Integer
Dim quantity As Variant
Dim unique_identifier As Integer
Dim lastrow_updated As Integer
Dim lastrow_preupload As Integer
Dim wiersz
Dim asset As String
Dim state As String
Dim old_row As Integer
Dim amp As String
Dim loaded
Dim direction_column As Integer
Dim delivery_type As String
Sheets("Calls").Select
ThisWorkbook.Save
customView = False
amntReplaced = False
Application.ScreenUpdating = False
Set wbmCall = ThisWorkbook
asset_column = Cells.Find(What:="Asset", After:=[A1], LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False).Column
quantity_column = Cells.Find(What:="Quantity", After:=[A1], LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False).Column
srchRange = Cells.Find(What:="Agmt Code", After:=[A1], LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False).Column
direction_column = Cells.Find(What:="Direction", After:=[A1], LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False).Column
xlsFile = Application.GetOpenFilename("Excel Workbooks (*.xls; *.xlsx),*.xls;*.xslx", , "Select Acadia extract to import.", , False)
If xlsFile = "False" Then Exit Sub
Set wbResults = Workbooks.Open(Filename:=xlsFile, UpdateLinks:=0)
' call amtcalled removed
Dim relocList() As Variant
Dim lngPosition As Integer
Dim startingRow As Range
Dim i As Long
Dim temporary_row As Integer
wbmCall.Activate
Dim b As Integer
Sheets("AcadiaFeeds").Select
Dim amp_array()
If Range("J65536").End(xlUp).Row > 2 Then
Cells(Range("J65536").End(xlUp).Row, 10).Select 'last row
lastrow_preupload = Range("J65536").End(xlUp).Row
amp_array = Range(Selection, Selection.End(xlUp))
End If
wbResults.Activate
'________________
For i = 2 To lastrow_preupload
If Range("Z" & i).Value = "Deliver" Then
ActiveSheet.Range("E" & i).Select
Selection.Replace What:="GROSS", Replacement:="OTM", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False, FormulaVersion:=xlReplaceFormula2
Else
ActiveSheet.Range("E" & i).Select
Selection.Replace What:="GROSS", Replacement:="ITM", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False, FormulaVersion:=xlReplaceFormula2
End If
Next i
'_______________________
relocList = Array("Margin Call Amp ID", "Delivery Type", "Amp ID", "Call Type", "Business State", "Valuation Date", "Total Call Amount", "Our Unique Agreement Identifier", "Quantity", "FX Currency", "Security Id", "Type")
Stop
For lngPosition = LBound(relocList) To UBound(relocList)
Set startingRow = ActiveSheet.Rows(1).Find(What:=relocList(lngPosition), After:=[A1], LookIn:=xlValues, LookAt:=xlWhole, _
SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:=False)
If Not startingRow Is Nothing Then
Columns(startingRow.Column).Select
Selection.Cut
Columns(1).Select
Selection.Insert Shift:=xlToRight
End If
Next lngPosition
Columns(13).Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Delete
Dim nextone As String
j = 1
i = 2
Do Until i = Range("A65000").End(xlUp).offset(1, 0).Row
If Cells(i, 8).Value = "Partial Disputed" Then
Rows(i).Delete
Else
i = i + 1
End If
If Cells(i, 11).Value = "Deliver" Then Cells(i, 11).Value = "Pledge"
If Cells(i, 1).Value = "PLEDGE" Then
temporary_row = WorksheetFunction.Match(Cells(i, 12), Range("J:J"), 0)
Cells(i, 5) = Cells(temporary_row, 5)
Cells(i, 8) = Cells(temporary_row, 8)
End If
Loop
Dim As String
i = 1
'remove blanks
=======================================================================================================================================================
lastRowNo = Range("A65000").End(xlUp).Row
wbmCall.Activate
Sheets("AcadiaFeeds").Select
If ActiveSheet.FilterMode = True Then ActiveSheet.FilterMode = False 'gdyby komus wpadl do lepetyny glupi pomysl dodawania filtra w Acadia Feeds
srchRowNo = Range("A65000").End(xlUp).Row + 5
If srchRowNo < 10 Then
srchRowNo = 10
lastrow_preupload = 10
End If
Range("L" & srchRowNo).Value = "Uploaded " & Format(Now, "mmm dd, yyyy hh:mm:ss") & " by " & LCase(Environ("USERNAME"))
srcRowNo = 1
i = 1
Do Until i > lastRowNo
Range("A" & srchRowNo & ":K" & srchRowNo).Value = wbResults.Sheets(1).Range("A" & srcRowNo & ":K" & srcRowNo).Value
srchRowNo = srchRowNo + 1
srcRowNo = srcRowNo + 1
i = i + 1
Loop
wbResults.Close SaveChanges:=False
Set wbResults = Nothing
wbmCall.Activate
Set wbmCall = Nothing
ActiveWorkbook.Sheets("Calls").Select
If ActiveSheet.AutoFilterMode = True Then
customView = True
Application.EnableEvents = False
ActiveWorkbook.CustomViews.Add ViewName:="doAcadii", RowColSettings:=True
ActiveSheet.AutoFilterMode = False
Application.EnableEvents = True
End If
ActiveWorkbook.Sheets("AcadiaFeeds").Select
callClmn = 5 'Our Unique Agreement Identifier na sztywno
cTypeClmn = 9 'call type na sztywno w kolumnie 5tej
=======================================================================================================================================================
backAtLoop:
srchRowNo = lastrow_preupload
lastrow_updated = Range("A65000").End(xlUp).Row
Do Until srchRowNo = lastrow_updated + 1
ActiveWorkbook.Sheets("AcadiaFeeds").Select
srchRowNo = srchRowNo + 1
amp = Cells(srchRowNo, callClmn + 5).Value ' amp ID
srchString = Cells(srchRowNo, callClmn).Value 'od dolu bierze unique identifier
callAmt = Cells(srchRowNo, callClmn + 1).Value 'amt called
cType = Cells(srchRowNo, cTypeClmn).Value 'call type
quantity = Cells(srchRowNo, callClmn - 1).Value 'ilosc papierow
state = Cells(srchRowNo, callClmn + 3).Value 'business state pledge accepted
delivery_type = Cells(srchRowNo, callClmn + 6)
typ = Cells(srchRowNo, 1).Value 'margin_call lub pledge
If Cells(srchRowNo, callClmn - 3).Value <> "CASH" Then
asset = Cells(srchRowNo, callClmn - 3).Value ' aktywo
Else:
asset = Cells(srchRowNo, callClmn - 2).Value
End If
Sheets("Calls").Select
Set foundmatchx = Columns(srchRange).Find(What:=srchString, LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False)
If typ = "MARGIN_CALL" Then
If Application.WorksheetFunction.CountIf(Columns(srchRange), srchString) = 0 Then 'sprawdza dany agreement jest w mcalls table
Sheets("AcadiaFeeds").Select
notFound = notFound & "; " & srchString
Range("A" & srchRowNo & ":I" & srchRowNo).Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 65535
.TintAndShade = 0
.PatternTintAndShade = 0
End With
Range("K" & srchRowNo).Value = "Not Found"
ElseIf Application.WorksheetFunction.CountIf(Columns(srchRange), srchString) <> 0 Then
'howMany = Application.WorksheetFunction.CountIf(Columns(srchRange), srchString)
foundmatchx.offset(0, 3).Activate ' aktywuje offset AMT called
If ActiveCell.offset(0, 11) = "Initial" And cType = "Initial" Then 'idk nor care
'nowt to do here
ElseIf cType = "Initial" And Right(srchString, 4) <> "FBCO" Then
ActiveWorkbook.Sheets("AcadiaFeeds").Select 'acadia feeds
Range("A" & srchRowNo & ":E" & srchRowNo).Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 49407
.TintAndShade = 0
.PatternTintAndShade = 0
End With
Range("F" & srchRowNo).Value = "IM call not found"
GoTo nexxtSrchRowNo
ElseIf cType = "Initial" And Right(srchString, 4) = "FBCO" Then
'nowt to do here
Else
Columns(srchRange).FindNext(foundmatchx).offset(0, 3).Activate
End If
Range("J" & srchRowNo).Value = "Already Loaded", Range("A" & srchRowNo & ":I" & srchRowNo).Select
If ActiveCell.Value = callAmt Then
ActiveWorkbook.Sheets("AcadiaFeeds").Select 'acadia feeds
With ActiveWorkbook.Sheets("AcadiaFeeds").Range("A" & srchRowNo & ":I" & srchRowNo).Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 5296274
.TintAndShade = 0
.PatternTintAndShade = 0
End With
Range("K" & srchRowNo).Value = "Already Loaded"
ElseIf ActiveCell.Value <> "" And ActiveCell.Value <> callAmt Then
ActiveWorkbook.Sheets("AcadiaFeeds").Select 'acadia feeds
Range("A" & srchRowNo & ":E" & srchRowNo).Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 49407
.TintAndShade = 0
.PatternTintAndShade = 0
End With
Range("K" & srchRowNo).Value = "Loaded w/ different amt - please investigate"
amntReplaced = True
Else
ActiveCell.Value = callAmt
ActiveCell.offset(0, 20).Value = "loaded from AcadiaFeeds sheet row# " & srchRowNo
End If
Else
MsgBox "Something unexpected happend"
End If
nexxtSrchRowNo:
End If
ActiveWorkbook.Sheets("AcadiaFeeds").Select
If typ = "PLEDGE" Then
Sheets("Calls").Select 'calls
wiersz = foundmatchx.Row
If IsVarArrayEmpty(amp_array) = False Then
j = 1
loaded = "not_loaded"
For j = 1 To UBound(amp_array)
If amp_array(j, 1) = amp Then
loaded = "already_loaded"
j = UBound(amp_array)
End If
Next
Else: loaded = "not_loaded"
End If
Select Case loaded
Case "already_loaded"
If state = "Pledge Accepted" Then
If IsEmpty(Cells(wiersz, quantity_column)) = False And quantity <> Cells(wiersz, quantity_column) Then
Application.Union(Range(Cells(wiersz + 1, srchRange - 2), Cells(wiersz + 1, srchRange - 1)), Range(Cells(wiersz + 1, srchRange + 1), Cells(wiersz + 1, srchRange + 2))).Style = "Good"
Else:
Application.Union(Range(Cells(wiersz, srchRange - 2), Cells(wiersz, srchRange - 1)), Range(Cells(wiersz, srchRange + 1), Cells(wiersz, srchRange + 2))).Style = "Good"
End If
End If
Case "not_loaded"
If delivery_type = Cells(wiersz, direction_column) And IsEmpty(Cells(wiersz, quantity_column)) = True Then
If state = "Pledge Accepted" Then
Application.Union(Range(Cells(wiersz, srchRange - 2), Cells(wiersz, srchRange - 1)), Range(Cells(wiersz, srchRange + 1), Cells(wiersz, srchRange + 2))).Style = "Good"
End If
Cells(wiersz, quantity_column) = quantity
Cells(wiersz, asset_column) = asset
ElseIf delivery_type = Cells(wiersz, direction_column) And IsEmpty(Cells(wiersz, quantity_column)) = False Then
Cells(wiersz, quantity_column).Select
Call MainModule.insertRow
Cells(wiersz + 1, quantity_column) = quantity
Cells(wiersz + 1, asset_column) = asset
If state = "Pledge Accepted" Then
Application.Union(Range(Cells(wiersz + 1, srchRange - 2), Cells(wiersz + 1, srchRange - 1)), Range(Cells(wiersz + 1, srchRange + 1), Cells(wiersz + 1, srchRange + 2))).Style = "Good"
End If
ElseIf delivery_type <> Cells(wiersz, direction_column) Then
howMany = Application.WorksheetFunction.CountIf(Columns(srchRange), srchString)
i = 1
For i = 1 To howMany
Set foundmatchx = Columns(srchRange).FindNext(foundmatchx)
'daje find dla danego agreeementu
temporary_row = foundmatchx.Row
If delivery_type = Cells(temporary_row, direction_column) And IsEmpty(Cells(temporary_row, quantity_column)) = True Then
'1_17 change
If state = "Pledge Accepted" Then
Application.Union(Range(Cells(temporary_row, srchRange - 2), Cells(temporary_row, srchRange - 1)), Range(Cells(temporary_row, srchRange + 1), Cells(temporary_row, srchRange + 2))).Style = "Good"
End If
Cells(temporary_row, quantity_column) = quantity
Cells(temporary_row, asset_column) = asset
i = howMany
End If
Next
End If
End Select
End If
Loop
ActiveWorkbook.Sheets("Calls").Select
'aplikuje filtr spowrotem
If customView = True Then
Application.EnableEvents = False
With ActiveWorkbook.CustomViews("doAcadii")
.Show
.Delete
End With
Application.EnableEvents = True
End If
Application.ScreenUpdating = True
'ponizsze IF dodane 07/30
If amntReplaced = True Then
MsgBox "Acadia extract uploaded, but some calls were loaded with different call amounts." & vbCrLf & _
"Please investigate for issues before saving this spreadsheet."
Else
MsgBox "Acadia extract uploaded!"
End If
End Sub
Sub amtsCalled()
Application.ScreenUpdating = False
Dim relocList() As Variant
Dim lngPosition As Integer
Dim startingRow As Range
Dim i As Long
Dim temporary_row As Integer
wbmCall.Activate
Sheets("AcadiaFeeds").Select
Dim amp_array()
Cells(Range("J65536").End(xlUp).Row, 10).Select 'last row
MsgBox (Cells(Range("J65536").End(xlUp).Row, 10))
amp_array = Range(Selection, Selection.End(xlUp))
wbResults.Activate
relocList = Array("Margin Call Amp ID", "Amp ID", "Call Type", "Business State", "Valuation Date", "Total Call Amount", "Our Unique Agreement Identifier", "Quantity", "FX Currency", "Security Id", "Type")
Stop
For lngPosition = LBound(relocList) To UBound(relocList)
Set startingRow = ActiveSheet.Rows(1).Find(What:=relocList(lngPosition), After:=[A1], LookIn:=xlValues, LookAt:=xlWhole, _
SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:=False)
If Not startingRow Is Nothing Then
Columns(startingRow.Column).Select
Selection.Cut
Columns(1).Select
Selection.Insert Shift:=xlToRight
End If
Next lngPosition
Columns(12).Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Delete
Dim nextone As String
i = 2
Do Until i = Range("A65000").End(xlUp).offset(1, 0).Row
For j = 1 To UBound(amp_array)
If Cells(i, 10).Value = amp_array(j, 1) Then GoTo nextone
Next
If Cells(i, 8).Value = "Partial Disputed" Then
Rows(i).Delete
Else
i = i + 1
End If
If Cells(i, 1).Value = "PLEDGE" Then
temporary_row = WorksheetFunction.Match(Cells(i, 11), Range("J:J"), 0)
Cells(i, 5) = Cells(temporary_row, 5)
End If
nextone:
Loop
'remove blanks
On Error GoTo 0
Exit Sub
Application.ScreenUpdating = True
End Sub
Sub ss()
Application.ScreenUpdating = True
End Sub
Function IsVarArrayEmpty(anArray As Variant)
Dim i As Integer
On Error Resume Next
i = UBound(anArray, 1)
If Err.Number = 0 Then
IsVarArrayEmpty = False
Else
IsVarArrayEmpty = True
End If
End Function
Some of the lines are in Polish, is this causing the issue with uploading new macros and working when it's unshared?
It looks like this is by design:
"Once you share a workbook, any Visual Basic project it contains is no longer accessible. Excel can’t deal with multiple users editing the same macros, so it simply prevents changes to those macros. You can’t record new macros, either. However, you can run macros from shared workbooks."
Ref: https://www.oreilly.com/library/view/programming-excel-with/0596007663/ch08s03.html

How to set content into mui-rte with selenium webdriver in python?

I am using mui-rte rich text editor (https://github.com/niuware/mui-rte) in a react project. I am not able to figure out how to input text to the rte input area when writing a selenium webdriver integration test.
As I understand correctly, mui-rte is a materia-ui wrapper of draftjs. The react code is simply:
<MUIRichTextEditor
onChange={onChange}
value={initial}
{...rest}
/ >
This generates the following html elements:
<div id="mui-rte-container" class="MUIRichTextEditor-container-73">
<div id="mui-rte-toolbar" class="MUIRichTextEditor-toolbar-84">
...
</div>
<div id="mui-rte-editor" class="MUIRichTextEditor-editor-75">
<div id="mui-rte-editor-container" class="MUIRichTextEditor-hidePlaceholder-79 MUIRichTextEditor-editorContainer-76">
<div class="DraftEditor-root">
<div class="DraftEditor-editorContainer">
<div aria-describedby="placeholder-9mnek" class="notranslate public-DraftEditor-content" role="textbox" spellcheck="false" style="outline:none;user-select:text;-webkit-user-select:text;white-space:pre-wrap;word-wrap:break-word" contenteditable="true">
<div data-contents="true"><div class="" data-block="true" data-editor="7kjuh" data-offset-key="8a2rc-0-0">
<div data-offset-key="8a2rc-0-0" class="public-DraftStyleDefault-block public-DraftStyleDefault-ltr">
<span data-offset-key="8a2rc-0-0">
<br data-text="true">
</span>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
I can easily find any of the element but when I try this for example:
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait # available since 2.4.0
from selenium.webdriver.support import expected_conditions as EC # available since 2.26.0
from selenium.webdriver.common.by import By
rte_editor = WebDriverWait(self.driver, 2).until(
EC.presence_of_element_located((By.ID, id))
)
rte_input = bio_rte.find_element_by_xpath("//div[#role='textbox']")
rte_input.send_keys("Hello")
I get:
E selenium.common.exceptions.ElementNotInteractableException: Message: Element <div class="notranslate public-DraftEditor-content"> is not reachable by keyboard
With all elements that I have tried.
What is the correct way to input text into draft.js rte with selenium-webdriver in python? I am quite new to selenium+webdriver and any help will be appreciated, be it in python, JavaScript or other flavor of selenium-webdriver API.
I have a sample project here: https://github.com/vessper/formik-mui-rte-example
update:
Including the stack trace from the error:
self = <test.TestBase testMethod=test_input_text_in_rte>
def test_input_text_in_rte(self):
rte_input = WebDriverWait(self.driver, 20).until(
EC.element_to_be_clickable(
> (By.XPATH, '//div[#class="notranslate public-DraftEditor-content" and #role="textbox"]'))
)
test.py:25:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <selenium.webdriver.support.wait.WebDriverWait (session="38c21bf5-27ea-499d-9831-e8755a10f57a")>
method = <selenium.webdriver.support.expected_conditions.element_to_be_clickable object at 0x7f7115fe7198>, message = ''
def until(self, method, message=''):
"""Calls the method provided with the driver as an argument until the \
return value is not False."""
screen = None
stacktrace = None
end_time = time.time() + self._timeout
while True:
try:
value = method(self._driver)
if value:
return value
except self._ignored_exceptions as exc:
screen = getattr(exc, 'screen', None)
stacktrace = getattr(exc, 'stacktrace', None)
time.sleep(self._poll)
if time.time() > end_time:
break
> raise TimeoutException(message, screen, stacktrace)
E selenium.common.exceptions.TimeoutException: Message:
../../../.virtualenvs/ml2/lib/python3.7/site-packages/selenium/webdriver/support/wait.py:80: TimeoutException
================================================================= 1 failed in 24.70s ==================================================================
In my case it was a draft.js rich text editor with a contenteditable div
async sendKeysToContentEditableDiv(element, text) {
const script = `var txtarea = arguments[0],txt = arguments[1];
txtarea.dispatchEvent(new Event("focus"));
var txtEvt = document.createEvent("TextEvent");
txtEvt.initTextEvent("textInput", true, true, null, txt);
txtarea.dispatchEvent(txtEvt);
txtarea.dispatchEvent(new Event("blur"));`;
await this.driver.executeScript(script, element, text);
}
The desired element is a ReactJS enabled element so to locate and send a character sequence to the element you have to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following solutions:
Using CSS_SELECTOR:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "div.notranslate.public-DraftEditor-content[role='textbox']"))).send_keys("Vess_Perfanov")
Using XPATH:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[#class='notranslate public-DraftEditor-content' and #role='textbox']"))).send_keys("Vess_Perfanov")
Note : You have to add the following imports :
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
Update
As the click() is still not invoked with WebDriverWait you can use ActionChains as follows:
Using CSS_SELECTOR:
element = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "div.notranslate.public-DraftEditor-content[role='textbox']"))).send_keys("Vess_Perfanov")
ActionChains(driver).move_to_element(element).click(element).send_keys("Vess_Perfanov").perform()
Using XPATH:
element = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[#class='notranslate public-DraftEditor-content' and #role='textbox']"))).send_keys("Vess_Perfanov")
ActionChains(driver).move_to_element(element).click(element).send_keys_to_element(element, "Vess_Perfanov").perform()
There is an inline label element from Material-UI that needs to be clicked first to uncover the underlying text field. So the following work for me.
from selenium import webdriver
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver import ActionChains
import unittest
class TestBase(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Firefox()
self.driver.get(URL)
def tearDown(self):
self.driver.close()
def get_by_id(self, id):
return WebDriverWait(self.driver, 5).until(
EC.presence_of_element_located((By.ID, id))
)
def test_input_text_in_rte(self):
description_msg = "Hello There"
rte_container = self.get_by_id('mui-rte-container')
rte_label = rte_container.find_element_by_xpath("//*[contains(text(), 'Description:')]")
actions = ActionChains(self.driver)
actions.move_to_element(rte_label)
actions.click(rte_label)
actions.perform()
rte_input = WebDriverWait(self.driver, 5).until(
EC.presence_of_element_located((By.XPATH,
'//div[#class="notranslate public-DraftEditor-content" and #role="textbox"]'))
)
rte_input.send_keys(description_msg)
Thanks to #DebanjanB for the suggestions that are incorporated in the code above.

Picker issue in codenameone

I have two pickers. The 2nd picker should be active as soon as the 1st picker is selected. But If the 2nd picker is clicked at first, the empty picker string is opened and then dialog stating choose the 1st picker is shown. How can I not show the empty picker string list if the first picker is not selected ?
Picker datePicker = new Picker();
datePicker.addActionListener(e -> {
SimpleDateFormat sf = new SimpleDateFormat("y");
String a = sf.format(datePicker.getDate());
SimpleDateFormat sf1 = new SimpleDateFormat("M");
String b = sf1.format(datePicker.getDate());
SimpleDateFormat sf2 = new SimpleDateFormat("d");
String c = sf2.format(datePicker.getDate());
getStartDate = a + "-" + b + "-" + c;
});
stationPicker.addActionListener(e -> {
if (!getStartDate.equals("")) {
_ _ _ _ _ _ _ _ _ ___ _
_ _ _ _ _ _ _ _ _ ___ _
}else{
Dialog.show("Warning", "Please choose the date first", "ok", null);
stationPicker.setSelectedString("Select the service center");
}
});
Have a look at the video so that the issue is more clear.
https://www.youtube.com/watch?v=Fmg13qm08Is

Updating the table and displaying the current data

I am trying to update the table which is working but after updating I cannnot see the updated data on the form when I ho to next record and comeback eventhough it gets updated on sql server.
Here is my code
Try
cn = Connection.connectionstringESLC()
cn.Open()
Dim query As String
query = "Update [School Admin Aug 2012] SET NAME='" & txtName.Text & _
"' , ADDRESS = '" & txtAddress.Text & _
"' , [Alternate Email] = '" & txtEmail.Text & _
"' , [ADVISOR NAME] = '" & txtAdvName.Text & _
"' , [DEPT NAME] = '" & txtDept.Text & _
"' , PROGRAM = '" & txtDegree.Text & _
"' , DEGREE = '" & txtMajor.Text & _
"', MAJOR = '" & txtProgram.Text & _
"', [DATE ADMITTED] = '" & dtpAdmitted.Value & _
"', [ADMISSION DECISION] = '" & cmbAdmDecision.Text & _
"' , [ENROLLMENT STATUS] = '" & cmbEnrollment.Text & _
"', [CAMPUS] = '" & cmbCampus.Text & _
"' , [ADVISING SHEET DATE] = '" & dtpAdvshtdt.Value & _
"' , [GRADUATION DATE] = '" & dtpGrdDt.Value & _
"' , [CURRENT POSITION] = '" & txtCurrentPosition.Text & _
"' , [GRE] = '" & txtGRE.Text & _
"' , [SLLA] = '" & txtSLLA.Text & _
"' , [KYPT] = '" & txtKYPT.Text & _
"' , [COMMENT] = '" & txtComment.Text & _
"' WHERE [MNUMBER] = '" & txtMNumber.Text & "'"
cmd = New SqlCommand(query, cn)
cmd.ExecuteNonQuery()
cn.Close()
cn = Nothing
MsgBox("Record updated successfully")
loadinfo()
Catch ex As Exception
MsgBox(ex.Message)
End Try
' I am also running loadinfo() code on page_load function
Public Sub loadinfo()
Try
cn = Connection.connectionstringESLC()
cn.Open()
cmd = New SqlCommand("Select * from [School Admin Aug 2012]")
cmd.Connection = cn
da.SelectCommand = cmd
da.Fill(ds, "dbo.School Admin Aug 2012")
da.Dispose()
cmd.Dispose()
If i < ds.Tables(0).Rows.Count - 1 Then
txtMNumber.Text = ds.Tables(0).Rows(i).Item(0)
txtName.Text = IIf(IsDBNull(ds.Tables(0).Rows(i).Item(1)), " ", ds.Tables(0).Rows(i).Item(1))
' IIf(IsDBNull(ds.Tables(0).Rows(0).Item(2)), " ", ds.Tables(0).Rows(0).Item(2))
txtAddress.Text = IIf(IsDBNull(ds.Tables(0).Rows(i).Item(2)), " ", ds.Tables(0).Rows(i).Item(2))
txtEmail.Text = IIf(IsDBNull(ds.Tables(0).Rows(i).Item(3)), " ", ds.Tables(0).Rows(i).Item(3))
txtAdvName.Text = IIf(IsDBNull(ds.Tables(0).Rows(i).Item(4)), " ", ds.Tables(0).Rows(i).Item(4))
txtDept.Text = IIf(IsDBNull(ds.Tables(0).Rows(i).Item(5)), " ", ds.Tables(0).Rows(i).Item(5))
txtProgram.Text = IIf(IsDBNull(ds.Tables(0).Rows(i).Item(6)), " ", ds.Tables(0).Rows(i).Item("PROGRAM"))
txtDegree.Text = IIf(IsDBNull(ds.Tables(0).Rows(i).Item(7)), " ", ds.Tables(0).Rows(i).Item("DEGREE"))
txtMajor.Text = IIf(IsDBNull(ds.Tables(0).Rows(i).Item(8)), " ", ds.Tables(0).Rows(i).Item("MAJOR"))
dtpAdmitted.Value = IIf(IsDBNull(ds.Tables(0).Rows(i).Item(9)), "12/31/9998", ds.Tables(0).Rows(i).Item(9))
cmbAdmDecision.Text = IIf(IsDBNull(ds.Tables(0).Rows(i).Item(10)), " ", ds.Tables(0).Rows(i).Item(10))
cmbEnrollment.Text = IIf(IsDBNull(ds.Tables(0).Rows(i).Item(11)), " ", ds.Tables(0).Rows(i).Item(11))
cmbCampus.Text = IIf(IsDBNull(ds.Tables(0).Rows(i).Item(12)), " ", ds.Tables(0).Rows(i).Item(12))
dtpAdvshtdt.Value = IIf(IsDBNull(ds.Tables(0).Rows(i).Item(13)), "12/31/9998", ds.Tables(0).Rows(i).Item(13))
dtpGrdDt.Value = IIf(IsDBNull(ds.Tables(0).Rows(i).Item(14)), "12/31/9998", ds.Tables(0).Rows(i).Item(14))
txtCurrentPosition.Text = IIf(IsDBNull(ds.Tables(0).Rows(i).Item(15)), " ", ds.Tables(0).Rows(i).Item(15))
txtGRE.Text = IIf(IsDBNull(ds.Tables(0).Rows(i).Item(16)), " ", ds.Tables(0).Rows(i).Item(16))
txtSLLA.Text = IIf(IsDBNull(ds.Tables(0).Rows(i).Item(17)), " ", ds.Tables(0).Rows(i).Item(17))
txtKYPT.Text = IIf(IsDBNull(ds.Tables(0).Rows(i).Item(18)), " ", ds.Tables(0).Rows(i).Item(18))
txtComment.Text = IIf(IsDBNull(ds.Tables(0).Rows(i).Item(19)), " ", ds.Tables(0).Rows(i).Item(19))
cn.Close()
cn = Nothing
ElseIf i < 0 Then
i = 0
Else
MsgBox("This is the last record")
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub

Resources